-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from npocccties/feat-page-components
feat: ページコンポーネントの実装
- Loading branch information
Showing
19 changed files
with
354 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import aspida from "@aspida/fetch"; | ||
import api from "api/$api"; | ||
|
||
export const client = api( | ||
aspida(fetch, { baseURL: process.env.NEXT_PUBLIC_API_BASE_URL }) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
frontend/pages/consumers/[consumerId]/frameworks/[frameworkId]/stages/[stageId].tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Error from "next/error"; | ||
import { client } from "lib/client"; | ||
import { Consumer, Framework, Stage, Field, BadgeDetail2 } from "api/@types"; | ||
import Template from "templates/Stage"; | ||
|
||
export type Context = { | ||
params: { consumerId: string; frameworkId: string; stageId: string }; | ||
}; | ||
|
||
type ErrorProps = { | ||
title: string; | ||
statusCode: number; | ||
}; | ||
|
||
export type Props = { | ||
consumer: Consumer; | ||
framework: Framework; | ||
stages: Stage[]; | ||
stage: Stage; | ||
fields: Field[]; | ||
wisdomBadgesMap: Map<number, BadgeDetail2[]>; | ||
}; | ||
|
||
export async function getServerSideProps({ | ||
params: { consumerId, frameworkId, stageId }, | ||
}: Context): Promise<{ props: ErrorProps | Props }> { | ||
const { body: consumer } = await client.consumer.get({ | ||
query: { consumer_id: Number(consumerId) }, | ||
}); | ||
const { body: framework } = await client.framework.get({ | ||
query: { framework_id: Number(frameworkId) }, | ||
}); | ||
const { body: stages } = await client.framework.stage.list.get({ | ||
query: { framework_id: Number(frameworkId) }, | ||
}); | ||
const stage = stages.find((stage) => stage.stage_id === Number(stageId)); | ||
if (!stage) return { props: { title: "Stage Not Found", statusCode: 404 } }; | ||
const { body: fields } = await client.stage.field.list.get({ | ||
query: { stage_id: Number(stageId) }, | ||
}); | ||
const wisdomBadgesMap = new Map<number, BadgeDetail2[]>(); | ||
const fieldIds = fields.flatMap(({ field1 }) => | ||
field1.flatMap(({ field2 }) => | ||
field2.flatMap(({ field3 }) => field3.flatMap(({ field_id }) => field_id)) | ||
) | ||
); | ||
for (const fieldId of fieldIds) { | ||
const { body: wisdomBadges } = await client.wisdomBadges.list.get({ | ||
query: { field_id: fieldId, stage_id: Number(stageId) }, | ||
}); | ||
wisdomBadgesMap.set(fieldId, wisdomBadges.badges); | ||
} | ||
return { | ||
props: { consumer, framework, stages, stage, fields, wisdomBadgesMap }, | ||
}; | ||
} | ||
|
||
export default function Page(props: ErrorProps | Props) { | ||
if ("statusCode" in props) | ||
return <Error title={props.title} statusCode={props.statusCode} />; | ||
return <Template {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { client } from "lib/client"; | ||
import { Consumer, Framework, Stage } from "api/@types"; | ||
import Template from "templates/Frameworks"; | ||
|
||
export type Context = { | ||
params: { consumerId: string }; | ||
}; | ||
|
||
export type Props = { | ||
consumer: Consumer; | ||
frameworks: Framework[]; | ||
stagesPerFrameworks: Stage[][]; | ||
}; | ||
|
||
export async function getServerSideProps({ | ||
params: { consumerId }, | ||
}: Context): Promise<{ | ||
props: Props; | ||
}> { | ||
const { body: consumer } = await client.consumer.get({ | ||
query: { consumer_id: Number(consumerId) }, | ||
}); | ||
const { body: frameworks } = await client.consumer.framework.list.get({ | ||
query: { consumer_id: Number(consumerId) }, | ||
}); | ||
const stagesPerFrameworks = await Promise.all( | ||
frameworks.map(({ framework_id }) => | ||
client.framework.stage.list.get({ query: { framework_id } }) | ||
) | ||
).then((value) => value.map((res) => res.body)); | ||
return { | ||
props: { consumer, frameworks, stagesPerFrameworks }, | ||
}; | ||
} | ||
|
||
export default Template; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,29 @@ | ||
import type { NextPage } from "next"; | ||
import Head from "next/head"; | ||
import Image from "next/image"; | ||
import styles from "../styles/Home.module.css"; | ||
|
||
const Home: NextPage = () => { | ||
return ( | ||
<div className={styles.container}> | ||
<Head> | ||
<title>Create Next App</title> | ||
<meta name="description" content="Generated by create next app" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
</Head> | ||
|
||
<main className={styles.main}> | ||
<h1 className={styles.title}> | ||
Welcome to <a href="https://nextjs.org">Next.js!</a> | ||
</h1> | ||
|
||
<p className={styles.description}> | ||
Get started by editing{" "} | ||
<code className={styles.code}>pages/index.tsx</code> | ||
</p> | ||
|
||
<div className={styles.grid}> | ||
<a href="https://nextjs.org/docs" className={styles.card}> | ||
<h2>Documentation →</h2> | ||
<p>Find in-depth information about Next.js features and API.</p> | ||
</a> | ||
|
||
<a href="https://nextjs.org/learn" className={styles.card}> | ||
<h2>Learn →</h2> | ||
<p>Learn about Next.js in an interactive course with quizzes!</p> | ||
</a> | ||
|
||
<a | ||
href="https://github.com/vercel/next.js/tree/canary/examples" | ||
className={styles.card} | ||
> | ||
<h2>Examples →</h2> | ||
<p>Discover and deploy boilerplate example Next.js projects.</p> | ||
</a> | ||
|
||
<a | ||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" | ||
className={styles.card} | ||
> | ||
<h2>Deploy →</h2> | ||
<p> | ||
Instantly deploy your Next.js site to a public URL with Vercel. | ||
</p> | ||
</a> | ||
</div> | ||
</main> | ||
|
||
<footer className={styles.footer}> | ||
<a | ||
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Powered by{" "} | ||
<span className={styles.logo}> | ||
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} /> | ||
</span> | ||
</a> | ||
</footer> | ||
</div> | ||
); | ||
import { client } from "lib/client"; | ||
import { Consumer, PortalCategory, BadgeDetail1 } from "api/@types"; | ||
import Template from "templates/Top"; | ||
|
||
export type Props = { | ||
articles: { title: string; slug: string }[]; | ||
recommendedWisdomBadgesList: BadgeDetail1[]; | ||
learningContents: { name: string; url: string }[]; | ||
consumers: Consumer[]; | ||
portalCategories: PortalCategory[]; | ||
}; | ||
|
||
export default Home; | ||
export async function getServerSideProps(): Promise<{ | ||
props: Props; | ||
}> { | ||
const { body: consumers } = await client.consumer.list.get(); | ||
const { body: portalCategories } = await client.portalCategory.list.get(); | ||
return { | ||
props: { | ||
articles: [], | ||
recommendedWisdomBadgesList: [], | ||
learningContents: [], | ||
consumers, | ||
portalCategories, | ||
}, | ||
}; | ||
} | ||
|
||
export default Template; |
Oops, something went wrong.