feat(striker-ui): add minimal demo

main
Tsu-ba-me 4 years ago
parent 28bdf4e1f2
commit 0b00a92a21
  1. 5
      striker-ui/.eslintignore
  2. 60
      striker-ui/.eslintrc.json
  3. 34
      striker-ui/.gitignore
  4. 1
      striker-ui/.husky/.gitignore
  5. 6
      striker-ui/.husky/commit-msg
  6. 7
      striker-ui/.husky/pre-commit
  7. 4
      striker-ui/.lintstagedrc.json
  8. 6
      striker-ui/.prettierrc.json
  9. 34
      striker-ui/README.md
  10. 3
      striker-ui/commitlint.config.js
  11. 22
      striker-ui/lib/Anvil/getAllAnvil.ts
  12. 23
      striker-ui/lib/Anvil/getOneAnvil.ts
  13. 20
      striker-ui/lib/Anvil/handleAPIGetAllAnvil.ts
  14. 28
      striker-ui/lib/Anvil/handleAPIGetOneAnvil.ts
  15. 7
      striker-ui/lib/consts/API_BASE_URL.ts
  16. 3
      striker-ui/lib/consts/IS_DEV_ENV.ts
  17. 5
      striker-ui/lib/fetchers/fetchJSON.ts
  18. 2
      striker-ui/next-env.d.ts
  19. 6199
      striker-ui/package-lock.json
  20. 40
      striker-ui/package.json
  21. 10
      striker-ui/pages/_app.tsx
  22. 20
      striker-ui/pages/api/anvils/[uuid].ts
  23. 20
      striker-ui/pages/api/anvils/index.ts
  24. 9
      striker-ui/pages/api/hello.ts
  25. 27
      striker-ui/pages/demo-anvil-list.tsx
  26. 32
      striker-ui/pages/demo-anvil-status.tsx
  27. 67
      striker-ui/pages/index.tsx
  28. BIN
      striker-ui/public/favicon.ico
  29. 4
      striker-ui/public/vercel.svg
  30. 122
      striker-ui/styles/Home.module.css
  31. 16
      striker-ui/styles/globals.css
  32. 21
      striker-ui/tsconfig.json
  33. 5
      striker-ui/types/APIRouteHandlerMap.d.ts
  34. 3
      striker-ui/types/AnvilList.d.ts
  35. 3
      striker-ui/types/AnvilListItem.d.ts
  36. 3
      striker-ui/types/AnvilNodeStatus.d.ts
  37. 4
      striker-ui/types/AnvilStatus.d.ts
  38. 3
      striker-ui/types/FetchResponse.d.ts
  39. 3
      striker-ui/types/GetAllAnvilResponse.d.ts
  40. 3
      striker-ui/types/GetOneAnvilResponse.d.ts

@ -0,0 +1,5 @@
# dependencies
/node_modules
# next.js
/.next/

@ -0,0 +1,60 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"airbnb",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/typescript",
"plugin:import/warnings",
"plugin:jsx-a11y/recommended",
"plugin:prettier/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"prettier/@typescript-eslint",
"prettier/react"
],
"plugins": [
"@typescript-eslint",
"import",
"jsx-a11y",
"prettier",
"react",
"react-hooks"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"complexity": ["error", 5],
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
],
// Allow JSX in files with other extensions
"react/jsx-filename-extension": [1, { "extensions": [".tsx"] }],
// Use TypeScript's types for component props
"react/prop-types": "off",
// Importing React is not required in Next.js
"react/react-in-jsx-scope": "off"
},
"settings": {
"react": { "version": "detect" }
}
}

@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel

@ -0,0 +1,6 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
cd striker-ui
npx --no-install commitlint --edit "$1"

@ -0,0 +1,7 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# Must cd because pwd/cwd is the root of this repository.
cd striker-ui
npx --no-install lint-staged

@ -0,0 +1,4 @@
{
"*.{js,jsx,ts,tsx}": "npm run lint -- --fix",
"*.{json,md}": "prettier --write"
}

@ -0,0 +1,6 @@
{
"endOfLine": "lf",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}

@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};

@ -0,0 +1,22 @@
import fetchJSON from '../fetchers/fetchJSON';
async function getAllAnvil(): Promise<GetAllAnvilResponse> {
const response: GetAllAnvilResponse = {
anvilList: {
anvils: [],
},
error: null,
};
try {
response.anvilList = await fetchJSON(
`${process.env.DATA_ENDPOINT_BASE_URL}/get_anvils`,
);
} catch (fetchError) {
response.error = fetchError;
}
return response;
}
export default getAllAnvil;

@ -0,0 +1,23 @@
import fetchJSON from '../fetchers/fetchJSON';
async function getOneAnvil(anvilUUID: string): Promise<GetOneAnvilResponse> {
const response: GetOneAnvilResponse = {
anvilStatus: {
nodes: [],
timestamp: 0,
},
error: null,
};
try {
response.anvilStatus = await fetchJSON(
`${process.env.DATA_ENDPOINT_BASE_URL}/get_anvil_status?anvil_uuid=${anvilUUID}`,
);
} catch (fetchError) {
response.error = fetchError;
}
return response;
}
export default getOneAnvil;

@ -0,0 +1,20 @@
import { NextApiRequest, NextApiResponse } from 'next';
import getAllAnvil from './getAllAnvil';
async function handleAPIGetAllAnvil(
request: NextApiRequest,
response: NextApiResponse,
): Promise<void> {
const { anvilList, error }: GetAllAnvilResponse = await getAllAnvil();
if (error) {
response.status(503);
} else {
response.status(200);
}
response.send(anvilList);
}
export default handleAPIGetAllAnvil;

@ -0,0 +1,28 @@
import { NextApiRequest, NextApiResponse } from 'next';
import getOneAnvil from './getOneAnvil';
async function handleAPIGetOneAnvil(
request: NextApiRequest,
response: NextApiResponse,
): Promise<void> {
const {
query: { uuid },
}: NextApiRequest = request;
const anvilUUID: string = uuid instanceof Array ? uuid[0] : uuid;
const { anvilStatus, error }: GetOneAnvilResponse = await getOneAnvil(
anvilUUID,
);
if (error) {
response.status(503);
} else {
response.status(200);
}
response.send(anvilStatus);
}
export default handleAPIGetOneAnvil;

@ -0,0 +1,7 @@
import IS_DEV_ENV from './IS_DEV_ENV';
const API_BASE_URL = IS_DEV_ENV
? process.env.DEVELOPMENT_API_BASE_URL
: process.env.PRODUCTION_API_BASE_URL;
export default API_BASE_URL;

@ -0,0 +1,3 @@
const IS_DEV_ENV: boolean = process.env.NODE_ENV !== 'production';
export default IS_DEV_ENV;

@ -0,0 +1,5 @@
function fetchJSON<T>(...args: [RequestInfo, RequestInit?]): Promise<T> {
return fetch(...args).then((response: Response) => response.json());
}
export default fetchJSON;

@ -0,0 +1,2 @@
/// <reference types="next" />
/// <reference types="next/types/global" />

File diff suppressed because it is too large Load Diff

@ -0,0 +1,40 @@
{
"name": "striker-ui",
"version": "0.1.0",
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev",
"lint": "eslint --config .eslintrc.json --ext js,jsx,ts,tsx --max-warnings=0",
"lint:dryrun": "npm run lint -- .",
"lint:fix": "npm run lint -- --fix .",
"postinstall": "cd .. && husky install striker-ui/.husky",
"start": "next start"
},
"dependencies": {
"next": "10.0.6",
"react": "17.0.1",
"react-dom": "17.0.1",
"swr": "^0.4.2"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@types/node": "^14.14.26",
"@types/react": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0",
"eslint": "^7.19.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^5.0.9",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"typescript": "^4.1.5"
}
}

@ -0,0 +1,10 @@
import '../styles/globals.css';
import { AppProps } from 'next/app';
function App({ Component, pageProps }: AppProps): JSX.Element {
// eslint-disable-next-line react/jsx-props-no-spreading
return <Component {...pageProps} />;
}
export default App;

@ -0,0 +1,20 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { APIRouteHandlerMap } from '../../../types/APIRouteHandlerMap';
import handleAPIGetOneAnvil from '../../../lib/Anvil/handleAPIGetOneAnvil';
const ROUTE_HANDLER_MAP: APIRouteHandlerMap = {
GET: handleAPIGetOneAnvil,
};
async function handleAPIOneAnvil(
request: NextApiRequest,
response: NextApiResponse,
): Promise<void> {
const { method: httpMethod = 'GET' }: NextApiRequest = request;
await ROUTE_HANDLER_MAP[httpMethod](request, response);
}
export default handleAPIOneAnvil;

@ -0,0 +1,20 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { APIRouteHandlerMap } from '../../../types/APIRouteHandlerMap';
import handleAPIGetAllAnvil from '../../../lib/Anvil/handleAPIGetAllAnvil';
const ROUTE_HANDLER_MAP: APIRouteHandlerMap = {
GET: handleAPIGetAllAnvil,
};
async function handleAPIAllAnvil(
request: NextApiRequest,
response: NextApiResponse,
): Promise<void> {
const { method: httpMethod = 'GET' }: NextApiRequest = request;
await ROUTE_HANDLER_MAP[httpMethod](request, response);
}
export default handleAPIAllAnvil;

@ -0,0 +1,9 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next';
function hello(req: NextApiRequest, res: NextApiResponse): void {
res.status(200).json({ name: 'John Doe' });
}
export default hello;

@ -0,0 +1,27 @@
import { GetServerSidePropsResult, InferGetServerSidePropsType } from 'next';
import API_BASE_URL from '../lib/consts/API_BASE_URL';
import fetchJSON from '../lib/fetchers/fetchJSON';
export async function getServerSideProps(): Promise<
GetServerSidePropsResult<AnvilList>
> {
return {
props: await fetchJSON(`${API_BASE_URL}/api/anvils`),
};
}
function DemoAnvilList({
anvils,
}: InferGetServerSidePropsType<typeof getServerSideProps>): JSX.Element {
return (
<div>
<h1>Demo Anvil List</h1>
<h2>anvils</h2>
<pre>{JSON.stringify(anvils, null, 4)}</pre>
</div>
);
}
export default DemoAnvilList;

@ -0,0 +1,32 @@
import { GetServerSidePropsResult, InferGetServerSidePropsType } from 'next';
import API_BASE_URL from '../lib/consts/API_BASE_URL';
import fetchJSON from '../lib/fetchers/fetchJSON';
export async function getServerSideProps(): Promise<
GetServerSidePropsResult<AnvilStatus>
> {
return {
props: await fetchJSON(
`${API_BASE_URL}/api/anvils/1aded871-fcb1-4473-9b97-6e9c246fc568`,
),
};
}
function DemoAnvilStatus({
nodes,
timestamp,
}: InferGetServerSidePropsType<typeof getServerSideProps>): JSX.Element {
return (
<div>
<h1>Demo Anvil List</h1>
<h2>nodes</h2>
<pre>{JSON.stringify(nodes, null, 4)}</pre>
<h2>timestamp</h2>
<pre>{timestamp}</pre>
</div>
);
}
export default DemoAnvilStatus;

@ -0,0 +1,67 @@
import Head from 'next/head';
import styles from '../styles/Home.module.css';
function Home(): JSX.Element {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<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.js</code>
</p>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h3>Documentation &rarr;</h3>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h3>Learn &rarr;</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/master/examples"
className={styles.card}
>
<h3>Examples &rarr;</h3>
<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}
>
<h3>Deploy &rarr;</h3>
<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{' '}
<img src="/vercel.svg" alt="Vercel Logo" className={styles.logo} />
</a>
</footer>
</div>
);
}
export default Home;

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -0,0 +1,4 @@
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1,122 @@
.container {
min-height: 100vh;
padding: 0 0.5rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.main {
padding: 5rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.footer {
width: 100%;
height: 100px;
border-top: 1px solid #eaeaea;
display: flex;
justify-content: center;
align-items: center;
}
.footer img {
margin-left: 0.5rem;
}
.footer a {
display: flex;
justify-content: center;
align-items: center;
}
.title a {
color: #0070f3;
text-decoration: none;
}
.title a:hover,
.title a:focus,
.title a:active {
text-decoration: underline;
}
.title {
margin: 0;
line-height: 1.15;
font-size: 4rem;
}
.title,
.description {
text-align: center;
}
.description {
line-height: 1.5;
font-size: 1.5rem;
}
.code {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Courier New, monospace;
}
.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
margin-top: 3rem;
}
.card {
margin: 1rem;
flex-basis: 45%;
padding: 1.5rem;
text-align: left;
color: inherit;
text-decoration: none;
border: 1px solid #eaeaea;
border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease;
}
.card:hover,
.card:focus,
.card:active {
color: #0070f3;
border-color: #0070f3;
}
.card h3 {
margin: 0 0 1rem 0;
font-size: 1.5rem;
}
.card p {
margin: 0;
font-size: 1.25rem;
line-height: 1.5;
}
.logo {
height: 1em;
}
@media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}

@ -0,0 +1,16 @@
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
a {
color: inherit;
text-decoration: none;
}
* {
box-sizing: border-box;
}

@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"noImplicitAny": true,
"typeRoots": ["types"]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}

@ -0,0 +1,5 @@
import { NextApiHandler } from 'next';
declare type APIRouteHandlerMap = Readonly<{
[httpMethod: string]: NextApiHandler;
}>;

@ -0,0 +1,3 @@
declare type AnvilList = {
anvils: AnvilListItem[];
};

@ -0,0 +1,3 @@
declare type AnvilListItem = {
uuid: string;
};

@ -0,0 +1,3 @@
declare type AnvilNodeStatus = {
on: 0 | 1;
};

@ -0,0 +1,4 @@
declare type AnvilStatus = {
nodes: AnvilNodeStatus[];
timestamp: number;
};

@ -0,0 +1,3 @@
declare type FetchResponse = {
error: Error | null;
};

@ -0,0 +1,3 @@
declare type GetAllAnvilResponse = FetchResponse & {
anvilList: AnvilList;
};

@ -0,0 +1,3 @@
declare type GetOneAnvilResponse = FetchResponse & {
anvilStatus: AnvilStatus;
};
Loading…
Cancel
Save