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

Commit

Permalink
Fix views crashing when description or content fields are null (#997)
Browse files Browse the repository at this point in the history
* FFix views crashing when description or content fields are null

* Refactor
  • Loading branch information
mmarkusik authored Feb 23, 2021
1 parent 5fec836 commit 5b0428e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
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

0 comments on commit 5b0428e

Please # to comment.