Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Fix views crashing when description or content fields are null #997

Merged
merged 2 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/views/Article/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { TypedArticleQuery } from "./query";

import "./scss/index.scss";

const canDisplay = page =>
maybe(() => !!page && !!page.title && !!page.content);
const canDisplay = page => !!page?.title;

const getHeaderImage = (collection: Article_collection) =>
maybe(() => collection.backgroundImage.url);

Expand Down
16 changes: 7 additions & 9 deletions src/views/Product/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@ import { channelSlug } from "@temp/constants";

import { MetaWrapper, NotFound } from "../../components";
import NetworkStatus from "../../components/NetworkStatus";
import { getGraphqlIdFromDBId, maybe } from "../../core/utils";
import { getGraphqlIdFromDBId } from "../../core/utils";
import { ProductDetails_product } from "./gqlTypes/ProductDetails";
import Page from "./Page";
import { TypedProductDetailsQuery } from "./queries";
import { IProps } from "./types";

import "./scss/index.scss";

const canDisplay = (product: ProductDetails_product) =>
maybe(
() =>
!!product.description &&
!!product.name &&
!!product.# &&
!!product.variants
);
const canDisplay = (product?: ProductDetails_product) =>
!!product?.name && !!product?.# && !!product?.variants;

const extractMeta = (product: ProductDetails_product, url: string) => ({
custom: [
{
Expand Down Expand Up @@ -127,6 +122,7 @@ const View: NextPage<ViewProps> = ({ query: { id } }) => {
<NetworkStatus>
{isOnline => {
const { product } = data;

if (canDisplay(product)) {
return (
<MetaWrapper
Expand All @@ -152,6 +148,8 @@ const View: NextPage<ViewProps> = ({ query: { id } }) => {
if (!isOnline) {
return <OfflinePlaceholder />;
}

return <NotFound />;
}}
</NetworkStatus>
)}
Expand Down