-
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 #13 from loxygenK/feat/home/api
- Loading branch information
Showing
15 changed files
with
137 additions
and
41 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
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,37 @@ | ||
import React from "react"; | ||
|
||
import styles from "./AwaitFetch.module.scss"; | ||
import { Emoji } from "./Emoji"; | ||
|
||
export type AwaitFetchProps<T> = { | ||
loading: boolean; | ||
error?: Error; | ||
data: NonNullable<T> | undefined; | ||
children: (data: NonNullable<T>) => React.ReactElement; | ||
}; | ||
|
||
// TypeScript recognizes <T> as JSX tag, however it doesn't when "<T,>". | ||
// (adding trail comma) | ||
export const AwaitFetch = <T,>({ | ||
loading, | ||
error, | ||
data, | ||
children, | ||
}: AwaitFetchProps<T>) => { | ||
if (error) | ||
return ( | ||
<p> | ||
<Emoji emoji="😵" /> | ||
読み込みに失敗しました! | ||
</p> | ||
); | ||
if (loading || data === undefined) | ||
return ( | ||
<p> | ||
<Emoji emoji="🔎" /> | ||
Loading... | ||
</p> | ||
); | ||
|
||
return children(data); | ||
}; |
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.
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,13 @@ | ||
.element { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.location { | ||
font-size: 1.25em; | ||
font-weight: 700; | ||
} | ||
|
||
.assign { | ||
font-size: 0.85em; | ||
} |
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,11 @@ | ||
import React from "react"; | ||
import { Affiliation as AffiliationEntity } from "~/api/graphql/autogen/scheme"; | ||
|
||
import styles from "./Affiriation.module.scss"; | ||
|
||
export const Affiliation: React.VFC<AffiliationEntity> = (props) => ( | ||
<div className={styles.element}> | ||
<span className={styles.location}>{props.location}</span> | ||
<span className={styles.assign}>{props.assign}</span> | ||
</div> | ||
); |
File renamed without changes.
File renamed without changes.
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,23 @@ | ||
import { gql, useQuery } from "@apollo/client"; | ||
import { Basic } from "~/api/graphql/autogen/scheme"; | ||
|
||
const fetchBasic = gql` | ||
query FetchBasic { | ||
basic { | ||
name { | ||
primary | ||
aka | ||
} | ||
introduction | ||
affiliation { | ||
location | ||
assign | ||
} | ||
age | ||
} | ||
} | ||
`; | ||
type FetchIntroductionResponse = { basic: Basic }; | ||
|
||
export const useBasicAPI = () => | ||
useQuery<FetchIntroductionResponse>(fetchBasic); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from "react"; | ||
import { AwaitFetch } from "~/comps/shared/AwaitFetch"; | ||
import { Affiliation } from "../atoms/Affiriation"; | ||
import { useBasicAPI } from "../controller"; | ||
|
||
import styles from "./Introduction.module.scss"; | ||
|
||
export const Introduction = () => { | ||
const { loading, error, data } = useBasicAPI(); | ||
|
||
return ( | ||
<AwaitFetch loading={loading} error={error} data={data}> | ||
{(data) => ( | ||
<div className={styles.wrapper}> | ||
<div className={styles.name}> | ||
<span className={styles.primary}>{data.basic.name.primary}</span> | ||
<span className={styles.aka}> | ||
{data.basic.name.aka.join(" / ")} | ||
</span> | ||
</div> | ||
<div className={styles.affiriation}> | ||
{data.basic.affiliation.map((a, key) => ( | ||
<Affiliation {...a} key={key} /> | ||
))} | ||
</div> | ||
<p>{data.basic.introduction}</p> | ||
</div> | ||
)} | ||
</AwaitFetch> | ||
); | ||
}; |
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
File renamed without changes.