Skip to content

Commit

Permalink
⚡ Slug bruker staticprops, oppdatert views
Browse files Browse the repository at this point in the history
  • Loading branch information
KenAJoh committed Dec 6, 2023
1 parent 09ac4d2 commit 380b448
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function GodPraksisPage(props: GpEntryPageProps) {
/>
</VStack>
</VStack>
<ArticleList views={props.views} />
<ArticleList articles={props.articles} />
</VStack>
</Page.Block>
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import ErrorBoundary from "@/error-boundary";
import { GpArticleViews } from "@/layout/god-praksis-page/types";
import { GpArticleListT } from "@/layout/god-praksis-page/types";
import ArticleGrid from "./ArticleGrid";

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

function ArticleList({ views }: GpArticleViews) {
return (
<>
{views.map((view) => (
<ArticleGrid
key={view.title}
name={view.title}
articles={markRandomAsNew(view.articles)}
/>
))}
</>
);
function ArticleList({ articles }: GpArticleListT) {
/* const router = useRouter();
const innholdstype = decodeURIComponent(router.query.innholdstype); */

return <ArticleGrid name="Siste" articles={markRandomAsNew(articles)} />;
}

export default function Component(props: GpArticleViews) {
export default function Component(props: GpArticleListT) {
return (
<ErrorBoundary boundaryName="Accordion">
<ArticleList {...props} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ function ChipNav({ type, options }: ChipsNavProps) {

function handleSelect(title: string) {
query[type] === title
? replace({ query: omit(query, [type]) }, undefined)
: replace({ query: { ...query, [type]: title } });
? replace({ query: omit(query, [type]) }, undefined, { shallow: true })
: replace({ query: { ...query, [type]: title } }, undefined, {
shallow: true,
});
}

return (
Expand All @@ -42,8 +44,9 @@ function ChipNav({ type, options }: ChipsNavProps) {
checkmark={false}
selected={encodeURIComponent(option) === query?.[type]}
onClick={() => handleSelect(encodeURIComponent(option))}
className="whitespace-nowrap"
>
{option}
{`${option} 4`}
</Chips.Toggle>
</li>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ export type GpInnholdstypeT = {
}[];
};

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

export type GpEntryPageProps = HeroNavT &
GpInnholdstypeT &
GpArticleViews &
GpArticleListT &
GpTemaT;
28 changes: 1 addition & 27 deletions aksel.nav.no/website/pages/gp/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ export const getStaticProps: GetStaticProps = async ({

return {
props: {
views: [
{
title: "Siste",
articles,
},
],
articles,
tema,
heroNav: heroNav.filter((x) => x.hasRefs),
innholdstype: innholdstype.filter((x) => x.hasRefs),
Expand Down Expand Up @@ -119,27 +114,6 @@ const Wrapper = (props: any) => {
params={{
slug: props?.slug,
}}
resolvers={[
{
key: "views",
dataKeys: ["articles"],
cb: (v) => {
return [
{
title: "Siste",
articles: v[0],
},
];
},
},
{
key: "articles",
dataKeys: ["articles"],
cb: () => {
return undefined;
},
},
]}
/>
</Suspense>
);
Expand Down
34 changes: 2 additions & 32 deletions aksel.nav.no/website/pages/gp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ export const getStaticProps: GetStaticProps = async ({
return {
props: {
tema: null,
views: [
{
title: "Siste",
articles,
},
],
articles,
heroNav: heroNav.filter((x) => x.hasRefs),
innholdstype: innholdstype.filter((x) => x.hasRefs),
preview,
Expand Down Expand Up @@ -82,32 +77,7 @@ const Wrapper = (props: any) => {
if (props?.preview) {
return (
<Suspense fallback={<GpPage {...props} />}>
<WithPreview
comp={GpPage}
query={query}
props={props}
resolvers={[
{
key: "views",
dataKeys: ["articles"],
cb: (v) => {
return [
{
title: "Siste",
articles: v[0],
},
];
},
},
{
key: "articles",
dataKeys: ["articles"],
cb: () => {
return undefined;
},
},
]}
/>
<WithPreview comp={GpPage} query={query} props={props} />
</Suspense>
);
}
Expand Down

0 comments on commit 380b448

Please sign in to comment.