Skip to content

Commit

Permalink
Merge pull request #13 from loxygenK/feat/home/api
Browse files Browse the repository at this point in the history
  • Loading branch information
loxygenK authored Nov 20, 2021
2 parents 6b71f19 + 915cff1 commit 6f39397
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/api/graphql/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Setupper, SetupperProps } from "../setup";

const apolloClient = new ApolloClient({
// TODO: Change this from the environment variable
uri: "http://localhost:8000",
uri: "http://localhost:8000/graphql",
cache: new InMemoryCache(),
});

Expand Down
37 changes: 37 additions & 0 deletions src/comps/shared/AwaitFetch.tsx
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);
};
6 changes: 5 additions & 1 deletion src/comps/shared/Emoji.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.emoji-default {
height: 1em;
display: inline-block;
height: 1.2em;
margin-right: 0.2em;

vertical-align: middle;

img {
height: 100%;
Expand Down
4 changes: 2 additions & 2 deletions src/comps/shared/LogoImage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ $pcpc-range: 10deg;

&.enable-animation {
animation:
1.5s 0.75s ease-out text-appear-scale,
0.75s 0.75s ease-out text-appear-opacity;
1.5s 0.75s ease-out forwards text-appear-scale,
0.75s 0.75s ease-out both text-appear-opacity;

g[id="main-text"] {
mask: url(#masker);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/about/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { PageWrapper } from "~/comps/layout/PageWrapper";
import { Heading } from "~/comps/shared/Heading";

import styles from "./About.module.scss";
import { Avatar } from "./Avatar";
import { Introduction } from "./Introduction";
import { Avatar } from "./atoms/Avatar";
import { Introduction } from "./organisms/Introduction";

export const About = () => (
<PageWrapper>
Expand Down
23 changes: 0 additions & 23 deletions src/pages/about/Introduction.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions src/pages/about/atoms/Affiriation.module.scss
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;
}
11 changes: 11 additions & 0 deletions src/pages/about/atoms/Affiriation.tsx
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.
23 changes: 23 additions & 0 deletions src/pages/about/controller.ts
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);
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
@use "~/styling/color.module.scss";
@use "~/styling/font.module.scss";

.wrapper {
%list {
display: flex;
flex-direction: column;
}

.wrapper {
@extend %list;
gap: 0.5em;
}

.name, .affiriation {
display: flex;
flex-direction: column;
.name {
@extend %list;
}

.primary {
Expand All @@ -20,15 +23,12 @@
line-height: 110%;
}

.element {
display: flex;
flex-direction: column;
}

.aka {
color: color.get-theme-color(text-color-secondary)
}

.location {
font-size: 1.25em;
.affiriation {
@extend %list;
gap: 0.5em;
}

31 changes: 31 additions & 0 deletions src/pages/about/organisms/Introduction.tsx
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>
);
};
2 changes: 1 addition & 1 deletion src/pages/splash/Splash.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { useHistory } from "react-router-dom";
import { combineClassName } from "~/utils/combineClassName";
import { TypingEffect } from "./comps/TypingEffect";
import { TypingEffect } from "./organisms/TypingEffect";
import styles from "./Splash.module.scss";

export const Splash = () => {
Expand Down
File renamed without changes.

0 comments on commit 6f39397

Please # to comment.