diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index 9d3f8c9d..ab14f1e6 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -77,7 +77,7 @@ export const FullArticle = (props: Props) => { const { t, formatDate, lang } = useLocalize() const { author, isAuthenticated, requireAuthentication } = useSession() - const formattedDate = createMemo(() => formatDate(new Date(props.article.published_at * 1000))) + const formattedDate = createMemo(() => formatDate(new Date((props.article?.published_at || 0) * 1000))) const canEdit = () => props.article.authors?.some((a) => Boolean(a) && a?.slug === author()?.slug) const mainTopic = createMemo(() => { diff --git a/src/components/Feed/ArticleCard/ArticleCard.tsx b/src/components/Feed/ArticleCard/ArticleCard.tsx index 31743db2..58f69cdf 100644 --- a/src/components/Feed/ArticleCard/ArticleCard.tsx +++ b/src/components/Feed/ArticleCard/ArticleCard.tsx @@ -117,7 +117,7 @@ export const ArticleCard = (props: ArticleCardProps) => { const { title, subtitle } = getTitleAndSubtitle(props.article) const formattedDate = createMemo(() => - props.article.published_at ? formatDate(new Date(props.article.published_at * 1000)) : '', + props.article?.published_at ? formatDate(new Date(props.article.published_at * 1000)) : '', ) const canEdit = () => diff --git a/src/context/editor.tsx b/src/context/editor.tsx index 9d40ec50..d2f1b82b 100644 --- a/src/context/editor.tsx +++ b/src/context/editor.tsx @@ -164,7 +164,7 @@ export const EditorProvider = (props: { children: JSX.Element }) => { const shout = await updateShout(formToSave, { publish: false }) removeDraftFromLocalStorage(formToSave.shoutId) - if (shout.published_at) { + if (shout?.published_at) { openPage(router, 'article', { slug: shout.slug }) } else { openPage(router, 'drafts') diff --git a/src/utils/sortby.ts b/src/utils/sortby.ts index 7566f577..9cd2182d 100644 --- a/src/utils/sortby.ts +++ b/src/utils/sortby.ts @@ -7,7 +7,7 @@ export const byCreated = (a: Shout | Reaction, b: Shout | Reaction) => { } export const byPublished = (a: Shout, b: Shout) => { - return a.published_at - b.published_at + return (a?.published_at || 0) - (b?.published_at || 0) } export const byLength = (