Skip to content

Commit 290cace

Browse files
committed
add skeleton
1 parent 9e47ca9 commit 290cace

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

marmite/components/Skeleton.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function Skeleton() {
2+
return (
3+
<div className="skeleton">
4+
<div className="s-banner"></div>
5+
<div className="s-header"></div>
6+
<div className="s-content"></div>
7+
<div className="s-content"></div>
8+
<div className="s-content"></div>
9+
<style jsx>{`
10+
.skeleton {
11+
max-width: 1200px;
12+
margin: 20px auto;
13+
}
14+
.skeleton > div {
15+
background: #dbcc1a;
16+
border-radius: 4px;
17+
margin: 20px 0;
18+
}
19+
.s-banner {
20+
padding: 12% 0;
21+
}
22+
.s-header {
23+
padding: 15px 0;
24+
max-width: 500px;
25+
}
26+
.s-content {
27+
padding: 8px 0;
28+
max-width: 1000px;
29+
}
30+
`}</style>
31+
</div>
32+
);
33+
}
34+
35+
export default Skeleton;

marmite/pages/recipes/[slug].js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createClient } from "contentful";
22
import { documentToReactComponents } from "@contentful/rich-text-react-renderer";
33
import Image from "next/image";
4+
import Skeleton from "../../components/Skeleton";
45

56
const client = createClient({
67
space: process.env.CONTENTFUL_SPACE_ID,
@@ -14,7 +15,10 @@ export const getStaticPaths = async () => {
1415
params: { slug: item.fields.slug },
1516
};
1617
});
17-
return { paths, fallback: false };
18+
return {
19+
paths,
20+
fallback: true, // handle new recipes
21+
};
1822
};
1923

2024
export async function getStaticProps({ params }) {
@@ -31,6 +35,8 @@ export async function getStaticProps({ params }) {
3135
}
3236

3337
export default function RecipeDetails({ recipe }) {
38+
if (!recipe) return <Skeleton />;
39+
3440
const {
3541
featuredImage,
3642
title,

0 commit comments

Comments
 (0)