Skip to content

Commit

Permalink
Extract common code to an article-list shared component
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcmoulton committed May 8, 2024
1 parent 4ab86fa commit b564c9d
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 14 deletions.
Expand Up @@ -3,6 +3,7 @@ import * as RA from 'fp-ts/ReadonlyArray';
import { pipe } from 'fp-ts/function';
import { renderListItems } from '../../../../../shared-components/render-list-items';
import { HtmlFragment, toHtmlFragment } from '../../../../../types/html-fragment';
import { renderArticleList } from '../../../shared-components/article-list';
import { PaginationControlsViewModel, renderPaginationControls } from '../../../shared-components/pagination';
import { renderPaperActivitySummaryCard } from '../../../shared-components/paper-activity-summary-card';
import { renderErrorAsHtml } from '../../../shared-components/paper-activity-summary-card/render-error-as-html';
Expand All @@ -18,9 +19,7 @@ const renderCards = (
(listContent) => `
<section class="group-page-feed">
<h2>Latest preprint reviews</h2>
<ol class="article-list" role="list">
${listContent}
</ol>
${renderArticleList(listContent)}
</section>
${renderPaginationControls(paginationControlsViewModel)}
`,
Expand Down
Expand Up @@ -6,6 +6,7 @@ import { HtmlFragment, toHtmlFragment } from '../../../../types/html-fragment';
import {
ArticleCardWithControlsAndAnnotationViewModel, renderArticleCardWithControlsAndAnnotation,
} from '../../shared-components/article-card-with-controls-and-annotation';
import { renderArticleList } from '../../shared-components/article-list';
import {
PaperActivityErrorCardViewModel, renderPaperActivityErrorCard,
} from '../../shared-components/paper-activity-summary-card';
Expand All @@ -24,6 +25,6 @@ export const renderArticlesList: RenderArticlesList = (articles) => pipe(
(articleCard) => renderArticleCardWithControlsAndAnnotation(articleCard),
)),
(listItems) => renderListItems(listItems),
(list) => `<ol class="article-list" role="list">${list}</ol>`,
(list) => renderArticleList(list),
toHtmlFragment,
);
Expand Up @@ -3,6 +3,7 @@ import * as RA from 'fp-ts/ReadonlyArray';
import { pipe } from 'fp-ts/function';
import { renderListItems } from '../../../../shared-components/render-list-items';
import { HtmlFragment, toHtmlFragment } from '../../../../types/html-fragment';
import { renderArticleList } from '../../shared-components/article-list';
import { renderAsHtml } from '../../shared-components/paper-activity-summary-card/render-as-html';
import { ViewModel } from '../view-model';

Expand All @@ -17,9 +18,7 @@ export const renderRelatedArticles = (viewmodel: ViewModel): HtmlFragment => pip
(listContent) => `
<div id="relatedArticles">
<h2 class="related-articles__header">Related articles</h2>
<ol class="article-list" role="list">
${listContent}
</ol>
${renderArticleList(listContent)}
</div>
`,
),
Expand Down
Expand Up @@ -3,16 +3,13 @@ import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray';
import { pipe } from 'fp-ts/function';
import { renderListItems } from '../../../../shared-components/render-list-items';
import { HtmlFragment, toHtmlFragment } from '../../../../types/html-fragment';
import { renderArticleList } from '../../shared-components/article-list';

export const renderSearchResultsList = (cards: ReadonlyArray<HtmlFragment>): O.Option<HtmlFragment> => pipe(
cards,
RNEA.fromReadonlyArray,
O.map(
(a) => `
<ol class="article-list" role="list">
${renderListItems(a)}
</ol>
`,
(a) => renderArticleList(renderListItems(a)),
),
O.map(toHtmlFragment),
);
1 change: 1 addition & 0 deletions src/read-side/html-pages/shared-components/_index.scss
@@ -1,4 +1,5 @@
@use 'article-card-with-controls-and-annotation';
@use 'article-list';
@use 'group-card';
@use 'group-link';
@use 'list-card';
Expand Down
@@ -1,4 +1,4 @@
@use '../../sass/list';
@use '../../../../sass/list';

.article-list {
@include list.basics();
Expand Down
@@ -0,0 +1 @@
export { renderArticleList } from './render-article-list';
@@ -0,0 +1,7 @@
import { HtmlFragment, toHtmlFragment } from '../../../../types/html-fragment';

export const renderArticleList = (listContent: HtmlFragment): HtmlFragment => toHtmlFragment(`
<ol class="article-list" role="list">
${listContent}
</ol>
`);
1 change: 0 additions & 1 deletion src/read-side/html-pages/style.scss
Expand Up @@ -5,7 +5,6 @@
@use 'shared-components';
@use 'form-rules';
@use 'layout-rules';
@use 'list-rules';
@use 'page-header';
@use 'about-page';
@use 'paper-activity-page/render-as-html';
Expand Down

1 comment on commit b564c9d

@davidcmoulton
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relates to ticket #3229

Please sign in to comment.