Skip to content

Commit

Permalink
Access the hardcoded query via dependencies #3342
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jun 20, 2024
1 parent aaf06e7 commit 7755839
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/http/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const createRouter = (dependencies: Dependencies, config: Config): Router
pageHandler(dependencies, flow(
searchResultsPageParams.decode,
E.fold(
() => searchPage,
() => searchPage(dependencies),
searchResultsPage(dependencies)(20),
),
)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as RA from 'fp-ts/ReadonlyArray';
import * as TE from 'fp-ts/TaskEither';
import { pipe } from 'fp-ts/function';
import { fetchSearchCategories } from '../../../../third-parties/fetch-search-categories';
import { Dependencies } from './dependencies';
import * as DE from '../../../../types/data-error';
import { ViewModel } from '../view-model';

export const constructViewModel = (): TE.TaskEither<DE.DataError, ViewModel> => pipe(
fetchSearchCategories(),
export const constructViewModel = (dependencies: Dependencies): TE.TaskEither<DE.DataError, ViewModel> => pipe(
dependencies.fetchSearchCategories(),
TE.map(RA.map((title) => ({
title,
href: `https://labs.sciety.org/categories/articles?category=${title}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ExternalQueries } from '../../../../third-parties';

export type Dependencies = ExternalQueries;
5 changes: 3 additions & 2 deletions src/read-side/html-pages/search-page/search-page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as TE from 'fp-ts/TaskEither';
import { pipe } from 'fp-ts/function';
import { constructViewModel } from './construct-view-model/construct-view-model';
import { Dependencies } from './construct-view-model/dependencies';
import { renderAsHtml } from './render-as-html/render-as-html';
import { constructErrorPageViewModel, ErrorPageViewModel } from '../construct-error-page-view-model';
import { HtmlPage } from '../html-page';

export const searchPage: TE.TaskEither<ErrorPageViewModel, HtmlPage> = pipe(
constructViewModel(),
export const searchPage = (dependencies: Dependencies): TE.TaskEither<ErrorPageViewModel, HtmlPage> => pipe(
constructViewModel(dependencies),
TE.bimap(constructErrorPageViewModel, renderAsHtml),
);

0 comments on commit 7755839

Please sign in to comment.