Skip to content

Commit

Permalink
🎨 Dynamic view of articles
Browse files Browse the repository at this point in the history
  • Loading branch information
KenAJoh committed Dec 5, 2023
1 parent e24d03a commit 30a903e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import Header from "@/layout/header/Header";
import ArticleList from "./articles/ArticleList";
import ChipNav from "./chips/ChipNav";
import Hero from "./hero/Hero";
import { GpArticleListT } from "./types";

type GodPraksisPageProps = GpArticleListT;

function GodPraksisPage({ articles }: GodPraksisPageProps) {
function GodPraksisPage() {
return (
/* TODO: Add surface-subtle to page-component props */
<Page
Expand All @@ -27,7 +24,7 @@ function GodPraksisPage({ articles }: GodPraksisPageProps) {
<ChipNav type="innholdstype" />
</VStack>
</VStack>
<ArticleList articles={articles} />
<ArticleList />
</VStack>
</Page.Block>
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { useGpPageContext } from "@/layout/god-praksis-page/context";
import ArticleGrid from "./ArticleGrid";

const markRandomAsNew = (articles) => {
return [...articles].map((a) => ({ ...a, isNew: Math.random() > 0.5 }));
};

function ArticleList({ articles }) {
if (!articles || articles.length === 0) {
return null;
}

const latest = markRandomAsNew(articles);
function ArticleList() {
const ctx = useGpPageContext();

return (
<>
{/* <ArticleBento name="Populære" articles={latest} /> */}
<ArticleGrid name="Siste" articles={latest} />

{ctx.views.map((view) => (
<ArticleGrid
key={view.title}
name={view.title}
articles={markRandomAsNew(view.articles)}
/>
))}
</>
);
}
Expand Down
13 changes: 11 additions & 2 deletions aksel.nav.no/website/components/layout/god-praksis-page/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export type GpInnholdstypeT = {
}[];
};

export type GpFrontPageProps = GpArticleListT & HeroNavT & GpInnholdstypeT;
export type GpArticleViews = {
views: ({
title: string;
} & GpArticleListT)[];
};

export type GpFrontPageProps = HeroNavT & GpInnholdstypeT & GpArticleViews;

export type GpTemaPageProps = HeroNavT & GpTemaT & GpInnholdstypeT;
export type GpTemaPageProps = HeroNavT &
GpTemaT &
GpInnholdstypeT &
GpArticleViews;
23 changes: 21 additions & 2 deletions aksel.nav.no/website/pages/gp/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
innholdstypeQuery,
} from "@/layout/god-praksis-page/queries";
import {
GpArticleListT,
GpInnholdstypeT,
GpTemaPageProps,
GpTemaT,
Expand All @@ -30,20 +31,38 @@ const query = groq`
title,
description
}
},
"articles": *[_type == "aksel_artikkel" && $slug in undertema[]->tema->slug.current] | order(publishedAt desc) {
heading,
ingress ,
"undertema": undertema[]->title,
"innholdstype": innholdstype->title,
"slug": slug.current
}
}
`;

export const getServerSideProps: GetServerSideProps = async (
ctx
): Promise<PageProps> => {
const { heroNav, tema, innholdstype }: HeroNavT & GpTemaT & GpInnholdstypeT =
const {
heroNav,
tema,
innholdstype,
articles,
}: HeroNavT & GpTemaT & GpInnholdstypeT & GpArticleListT =
await getClient().fetch(query, {
slug: ctx.params.slug,
});

return {
props: {
views: [
{
title: "Siste",
articles,
},
],
tema,
heroNav,
innholdstype,
Expand All @@ -64,7 +83,7 @@ const GpPage = (props: PageProps["props"]) => {
/* description={page?.seo?.meta} */
/* image={page?.seo?.image} */
/>
<GodPraksisPage articles={[]} />
<GodPraksisPage />
</GpPageContext.Provider>
);
};
Expand Down
11 changes: 8 additions & 3 deletions aksel.nav.no/website/pages/gp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const query = groq`
{
${heroNavQuery},
${innholdstypeQuery},
"articles": *[_type == "aksel_artikkel" && defined(undertema)] {
"articles": *[_type == "aksel_artikkel" && defined(undertema)] | order(publishedAt desc){
heading,
ingress ,
"undertema": undertema[]->title,
Expand All @@ -46,7 +46,12 @@ export const getServerSideProps: GetServerSideProps = async (

return {
props: {
articles,
views: [
{
title: "Siste",
articles,
},
],
heroNav,
innholdstype,
preview: ctx.preview ?? false,
Expand All @@ -65,7 +70,7 @@ const GpPage = (props: PageProps["props"]) => {
/* description={page?.seo?.meta} */
/* image={page?.seo?.image} */
/>
<GodPraksisPage articles={props.articles} />
<GodPraksisPage />
</GpPageContext.Provider>
);
};
Expand Down

0 comments on commit 30a903e

Please sign in to comment.