Skip to content

Commit

Permalink
Update latest additions (#421)
Browse files Browse the repository at this point in the history
* extract query latest into separate method

* update tests

* fix type error

* make result list responsive

* stack grid on mobile

* Refactoring responsive cols

* add spacing on mobile
  • Loading branch information
fsimonjetz authored Dec 27, 2023
1 parent 6bd7174 commit 2f22315
Show file tree
Hide file tree
Showing 10 changed files with 15,464 additions and 15,424 deletions.
1 change: 1 addition & 0 deletions src/fragmentarium/application/FragmentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const fragmentRepository = {
lineToVecRanking: jest.fn(),
findInCorpus: jest.fn(),
query: jest.fn(),
queryLatest: jest.fn(),
listAllFragments: jest.fn(),
queryByTraditionalReferences: jest.fn(),
}
Expand Down
5 changes: 5 additions & 0 deletions src/fragmentarium/application/FragmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface FragmentRepository {
fetchCdliInfo(cdliNumber: string): Bluebird<CdliInfo>
lineToVecRanking(number: string): Bluebird<LineToVecRanking>
query(fragmentQuery: FragmentQuery): Bluebird<QueryResult>
queryLatest(): Bluebird<QueryResult>
queryByTraditionalReferences(
traditionalReferences: string[]
): Bluebird<FragmentAfoRegisterQueryResult>
Expand Down Expand Up @@ -338,6 +339,10 @@ export class FragmentService {
return this.fragmentRepository.query(fragmentQuery)
}

queryLatest(): Bluebird<QueryResult> {
return this.fragmentRepository.queryLatest()
}

queryByTraditionalReferences(
traditionalReferences: string[]
): Bluebird<FragmentAfoRegisterQueryResult> {
Expand Down
18 changes: 14 additions & 4 deletions src/fragmentarium/infrastructure/FragmentRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ function createQueryItem(dto): QueryItem {
}
}

function createQueryResult(dto): QueryResult {
return {
matchCountTotal: dto.matchCountTotal,
items: dto.items.map(createQueryItem),
}
}

class ApiFragmentRepository
implements FragmentInfoRepository, FragmentRepository, AnnotationRepository {
constructor(private readonly apiClient: JsonApiClient) {}
Expand Down Expand Up @@ -381,10 +388,13 @@ class ApiFragmentRepository
query(fragmentQuery: FragmentQuery): Promise<QueryResult> {
return this.apiClient
.fetchJson(`/fragments/query?${stringify(fragmentQuery)}`, false)
.then((result) => ({
matchCountTotal: result.matchCountTotal,
items: result.items.map(createQueryItem),
}))
.then(createQueryResult)
}

queryLatest(): Promise<QueryResult> {
return this.apiClient
.fetchJson('/fragments/latest', false)
.then(createQueryResult)
}

queryByTraditionalReferences(
Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/ui/front-page/Fragmentarium.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Fragment lists', () => {
beforeEach(async () => {
latest = fragmentFactory.build()
session = new MemorySession(['read:fragments', 'transliterate:fragments'])
fragmentService.query.mockReturnValueOnce(
fragmentService.queryLatest.mockReturnValueOnce(
Promise.resolve({ items: [queryItemOf(latest)], matchCountTotal: 0 })
)
fragmentService.find.mockReturnValueOnce(Promise.resolve(latest))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ beforeEach(async () => {
{},
{ transient: { chance } }
)
fragmentService.query.mockReturnValueOnce(
fragmentService.queryLatest.mockReturnValueOnce(
Promise.resolve({
items: fragments.map(queryItemOf),
matchCountTotal: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/ui/front-page/LatestTransliterations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export default withData<
<LatestTransliterations data={data} fragmentService={fragmentService} />
)
},
(props) => props.fragmentService.query({ latest: true })
(props) => props.fragmentService.queryLatest()
)
Loading

0 comments on commit 2f22315

Please sign in to comment.