Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
gestchild committed Sep 17, 2024
1 parent c42795f commit e47ccee
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 54 deletions.
18 changes: 10 additions & 8 deletions common/services/prismic/link-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,47 @@ import { isContentType } from './content-types';

type Props = {
id: string;
uid: string;
type: string;
};
type DataProps = {
id: string;
uid: string;
type: string;
data: {
relatedDocument?: {
id: string;
uid: string;
type: string;
};
};
};
function linkResolver(doc: Props | DataProps): string {
const { id, type } = doc;

if (type === 'webcomics') return `/articles/${id}`;
if (type === 'webcomic-series') return `/series/${id}`;
const { uid, id, type } = doc;
if (type === 'webcomics') return `/articles/${uid}`;
if (type === 'webcomic-series') return `/series/${uid}`;
if (
type === 'exhibition-guides' ||
type === 'exhibition-texts' ||
type === 'exhibition-highlight-tours'
)
return `/guides/exhibitions/${id}`;
return `/guides/exhibitions/${uid}`;

if (type === 'visual-stories') {
if ('data' in doc) {
const {
data: { relatedDocument },
} = doc;
if (relatedDocument?.id) {
return `/${relatedDocument.type}/${relatedDocument.id}/visual-stories`;
if (relatedDocument?.uid) {
return `/${relatedDocument.type}/${relatedDocument.uid}/visual-stories`;
} else {
return `/visual-stories/${id}`;
}
}
}

if (isContentType(type)) {
return `/${type}/${id}`;
return `/${type}/${uid}`;
}

return '/';
Expand Down
5 changes: 3 additions & 2 deletions content/webapp/components/BookPromo/BookPromo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BookBasic } from '@weco/content/types/books';
import Space from '@weco/common/views/components/styled/Space';
import LabelsList from '@weco/common/views/components/LabelsList/LabelsList';
import BookImage from '@weco/content/components/BookImage/BookImage';
import linkResolver from '@weco/common/services/prismic/link-resolver';

type LinkSpaceAttrs = {
$url: string;
Expand Down Expand Up @@ -56,9 +57,9 @@ type Props = {
};

const BookPromo: FunctionComponent<Props> = ({ book }) => {
const { id, title, subtitle, promo, cover } = book;
const { title, subtitle, promo, cover } = book;
return (
<LinkSpace $url={`/books/${id}`}>
<LinkSpace $url={linkResolver(book)}>
<Space $v={{ size: 'l', properties: ['margin-bottom'] }}>
<BookImage
image={{
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/components/EventCard/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { font } from '@weco/common/utils/classnames';
import { getCrop } from '@weco/common/model/image';
import Space from '@weco/common/views/components/styled/Space';
import WatchLabel from '@weco/content/components/WatchLabel/WatchLabel';
import linkResolver from '@weco/common/services/prismic/link-resolver';

type Props = {
event: EventBasic;
Expand Down Expand Up @@ -70,7 +71,7 @@ const EventCard: FunctionComponent<Props> = ({ event, xOfY }) => {

return (
<CompactCard
url={`/events/${event.id}`}
url={linkResolver(event)}
title={event.title}
primaryLabels={event.primaryLabels}
secondaryLabels={event.secondaryLabels}
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/components/Exhibition/Exhibition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
ResourceLink,
ResourceLinkIconWrapper,
} from '@weco/content/components/styled/AccessResources';
import linkResolver from '@weco/common/services/prismic/link-resolver';

function getBorderColor({
type,
Expand Down Expand Up @@ -220,7 +221,7 @@ const Exhibition: FunctionComponent<Props> = ({
text: 'Exhibitions',
},
{
url: `/exhibitions/${exhibition.id}`,
url: linkResolver(exhibition),
text: exhibition.title,
isHidden: true,
},
Expand Down
2 changes: 1 addition & 1 deletion content/webapp/components/FeaturedCard/FeaturedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function convertItemToFeaturedCardProps(
},
labels: item.labels,
link: {
url: linkResolver({ id: item.id, type: item.type }),
url: linkResolver({ id: item.id, uid: item.uid, type: item.type }),
text: item.title,
},
};
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/components/Installation/Installation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ContentPage from '../ContentPage/ContentPage';
import { isNotUndefined } from '@weco/common/utils/type-guards';
import { fetchExhibitExhibition } from '../../services/prismic/fetch/exhibitions';
import { createScreenreaderLabel } from '@weco/common/utils/telephone-numbers';
import linkResolver from '@weco/common/services/prismic/link-resolver';

type Props = {
installation: InstallationType;
Expand Down Expand Up @@ -43,7 +44,7 @@ const Installation: FunctionComponent<Props> = ({ installation }) => {
}
: undefined,
{
url: `/exhibitions/${installation.id}`,
url: linkResolver(installation),
text: installation.title,
isHidden: true,
},
Expand Down
12 changes: 6 additions & 6 deletions content/webapp/components/SearchResults/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ArticleCard from '../ArticleCard/ArticleCard';
import { getCrop } from '@weco/common/model/image';
import { Card } from '../../types/card';
import PlainList from '@weco/common/views/components/styled/PlainList';
import linkResolver from '@weco/common/services/prismic/link-resolver';

const Result = styled.li`
border-top: 1px solid ${props => props.theme.color('warmNeutral.400')};
Expand Down Expand Up @@ -43,7 +44,6 @@ const SearchResults: FunctionComponent<Props> = ({
{summary && (
<Space $v={{ size: 'l', properties: ['margin-bottom'] }}>{summary}</Space>
)}

{items.length > 0 && (
<PlainList>
{items.map((item, index) => (
Expand Down Expand Up @@ -83,7 +83,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'pages' && (
<CompactCard
url={`/pages/${item.id}`}
url={linkResolver(item)}
title={item.title || ''}
primaryLabels={[]}
secondaryLabels={[]}
Expand Down Expand Up @@ -118,7 +118,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'event-series' && (
<CompactCard
url={`/event-series/${item.id}`}
url={linkResolver(item)}
title={item.title}
primaryLabels={item.labels}
secondaryLabels={[]}
Expand Down Expand Up @@ -153,7 +153,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'books' && (
<CompactCard
url={`/books/${item.id}`}
url={linkResolver(item)}
title={item.title}
primaryLabels={item.labels}
secondaryLabels={[]}
Expand Down Expand Up @@ -195,7 +195,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'series' && (
<CompactCard
url={`/series/${item.id}`}
url={linkResolver(item)}
title={item.title || ''}
primaryLabels={item.labels}
secondaryLabels={[]}
Expand Down Expand Up @@ -236,7 +236,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'exhibitions' && (
<CompactCard
url={`/exhibitions/${item.id}`}
url={linkResolver(item)} // TODO type?
title={item.title}
primaryLabels={item.labels}
secondaryLabels={[]}
Expand Down
15 changes: 9 additions & 6 deletions content/webapp/pages/articles/[articleId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { createPrismicLink } from '@weco/common/views/components/ApiToolbar';
import { setCacheControl } from '@weco/content/utils/setCacheControl';
import { isNotUndefined } from '@weco/common/utils/type-guards';
import Standfirst from '@weco/common/views/slices/Standfirst';
import linkResolver from '@weco/common/services/prismic/link-resolver';

const ContentTypeWrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -202,13 +203,15 @@ const ArticlePage: FunctionComponent<Props> = ({ article, jsonLd }) => {
// GOTCHA: we only take the first of the series list as the data is being
// used a little bit badly, but we don't have capacity to implement a
// better solution
...article.series.slice(0, 1).map(series => ({
url: `/series/${series.id}`,
text: series.title || '',
prefix: 'Part of',
})),
...article.series.slice(0, 1).map(series => {
return {
url: linkResolver(series),
text: series.title || '',
prefix: 'Part of',
};
}),
{
url: `/articles/${article.id}`,
url: linkResolver(article),
text: article.title,
isHidden: true,
},
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/pages/books/[bookId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Pageview } from '@weco/common/services/conversion/track';
import { createPrismicLink } from '@weco/common/views/components/ApiToolbar';
import { setCacheControl } from '@weco/content/utils/setCacheControl';
import { isNotUndefined } from '@weco/common/utils/type-guards';
import linkResolver from '@weco/common/services/prismic/link-resolver';

const MetadataWrapper = styled.div`
border-top: 1px solid ${props => props.theme.color('neutral.300')};
Expand Down Expand Up @@ -139,7 +140,7 @@ const BookPage: FunctionComponent<Props> = props => {
url: '/books',
},
{
url: `/books/${book.id}`,
url: linkResolver(book),
text: book.title,
isHidden: true,
},
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/pages/event-series/[eventSeriesId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { PaginatedResults } from '@weco/common/services/prismic/types';
import PaginationWrapper from '@weco/common/views/components/styled/PaginationWrapper';
import Pagination from '@weco/content/components/Pagination/Pagination';
import { getPage } from '@weco/content/utils/query-params';
import linkResolver from '@weco/common/services/prismic/link-resolver';

type Props = {
series: EventSeries;
Expand Down Expand Up @@ -130,7 +131,7 @@ const EventSeriesPage: FunctionComponent<Props> = ({
text: 'Events',
},
{
url: `/events-series/${series.id}`,
url: linkResolver(series),
text: series.title,
isHidden: true,
},
Expand Down
17 changes: 10 additions & 7 deletions content/webapp/pages/events/[eventId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,23 @@ const EventPage: NextPage<EventProps> = ({
url: '/events',
text: 'Events',
},
...event.series.map(series => ({
url: `/event-series/${series.id}`,
text: series.title || '',
prefix: 'Part of',
})),
...event.series.map(series => {
console.log(series);
return {
url: linkResolver(series),
text: series.title || '',
prefix: 'Part of',
};
}),
scheduledIn
? {
url: `/events/${scheduledIn.id}`,
url: linkResolver(scheduledIn),
text: scheduledIn.title || '',
prefix: 'Part of',
}
: undefined,
{
url: `/events/${event.id}`,
url: linkResolver(event),
text: event.title,
isHidden: true,
},
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/pages/events/[eventId]/visual-stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const getServerSideProps = async context => {
const visualStoryDocument = visualStoriesQuery.results.find(result => {
return (
isFilledLinkToDocument(result.data.relatedDocument) &&
result.data.relatedDocument.id === context.query.eventId
(result.data.relatedDocument.uid === context.query.eventId ||
result.data.relatedDocument.id === context.query.eventId)
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const getServerSideProps = async context => {
const visualStoryDocument = visualStoriesQuery.results.find(result => {
return (
isFilledLinkToDocument(result.data.relatedDocument) &&
result.data.relatedDocument.id === context.query.exhibitionId
(result.data.relatedDocument.uid === context.query.exhibitionId ||
result.data.relatedDocument.id === context.query.exhibitionId)
);
});

Expand Down
17 changes: 12 additions & 5 deletions content/webapp/pages/pages/[pageId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
import { gridSize12 } from '@weco/common/views/components/Layout';
import { isVanityUrl } from '@weco/content/utils/urls';
import { makeLabels } from '@weco/common/views/components/LabelsList/LabelsList';
import linkResolver from '@weco/common/services/prismic/link-resolver';

export type Props = {
page: PageType;
Expand All @@ -69,6 +70,7 @@ export type Props = {

type OrderInParent = {
id: string;
uid: string;
title: string;
order: number;
type: 'pages' | 'exhibitions';
Expand Down Expand Up @@ -134,6 +136,7 @@ export const getServerSideProps: GetServerSideProps<
page.parentPages?.map(p => {
return {
id: p.id,
uid: p.uid,
title: p.title,
order: p.order,
type: p.type,
Expand Down Expand Up @@ -247,11 +250,15 @@ export const Page: FunctionComponent<Props> = ({
const breadcrumbs = {
items: [
...sectionItem,
...ordersInParents.map(siblingGroup => ({
url: `/${siblingGroup.type}/${siblingGroup.id}`,
text: siblingGroup.title || '',
prefix: `Part ${siblingGroup.order || ''} of`,
})),
...ordersInParents.map(siblingGroup => {
console.log('HEY');
console.log({ siblingGroup });
return {
url: linkResolver(siblingGroup),
text: siblingGroup.title || '',
prefix: `Part ${siblingGroup.order || ''} of`,
};
}),
],
};

Expand Down
3 changes: 2 additions & 1 deletion content/webapp/pages/series/[seriesId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import ArticleScheduleItemCard from '@weco/content/components/ArticleScheduleIte
import { setCacheControl } from '@weco/content/utils/setCacheControl';
import Standfirst from '@weco/common/views/slices/Standfirst';
import { fetchSeriesById } from '../../services/prismic/fetch/series';
import linkResolver from '@weco/common/services/prismic/link-resolver';

const SeriesItem = styled.div<{ $isFirst: boolean }>`
border-top: ${props =>
Expand Down Expand Up @@ -185,7 +186,7 @@ const ArticleSeriesPage: FunctionComponent<Props> = props => {
text: 'Stories',
},
{
url: `/series/${series.id}`,
url: linkResolver(series),
text: series.title,
isHidden: true,
},
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/pages/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const getServerSideProps: GetServerSideProps<
const storiesLanding =
storiesLandingDoc &&
transformStoriesLanding(storiesLandingDoc as RawStoriesLandingDocument);

console.log(storiesLandingDoc.books);
if (articles && articles.results) {
return {
props: serialiseProps({
Expand Down Expand Up @@ -288,6 +288,7 @@ const StoriesPage: FunctionComponent<Props> = ({
</Layout>
</SpacingComponent>
)}
<pre>{JSON.stringify(storiesLanding.books, null, 2)}</pre>
<SpacingComponent>
<CardGrid
items={storiesLanding.books}
Expand Down
Loading

0 comments on commit e47ccee

Please sign in to comment.