Skip to content

Commit e07a02f

Browse files
authored
feat: implement container (#705)
1 parent da8095f commit e07a02f

File tree

13 files changed

+602
-73
lines changed

13 files changed

+602
-73
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/graphql/api.ts
2+
src/graphql/introspection-result.ts

.github/workflows/ts.yml

+22-23
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@ name: Node.js CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88

99
jobs:
1010
build:
11-
1211
runs-on: ubuntu-latest
1312
steps:
14-
- uses: actions/checkout@v2
15-
- name: Use Node.js
16-
uses: actions/setup-node@v1
17-
with:
18-
node-version: '12.x'
19-
- name: Install dependencies
20-
run: yarn
21-
- name: Lint
22-
run: yarn lint
23-
- name: Typing
24-
run: yarn tsc
25-
env:
26-
CI: true
27-
- name: bundle
28-
run: yarn build
29-
- name: Deploy
30-
uses: peaceiris/actions-gh-pages@v3
31-
with:
32-
github_token: ${{ secrets.GITHUB_TOKEN }}
33-
publish_dir: ./public
13+
- uses: actions/checkout@v2
14+
- name: Use Node.js
15+
uses: actions/setup-node@v1
16+
with:
17+
node-version: '12.x'
18+
- name: Install dependencies
19+
run: yarn
20+
- name: Lint
21+
run: yarn lint
22+
- name: Typing
23+
run: yarn tsc
24+
env:
25+
CI: true
26+
- name: bundle
27+
run: yarn build
28+
- name: Deploy
29+
uses: peaceiris/actions-gh-pages@v3
30+
with:
31+
github_token: ${{ secrets.GITHUB_TOKEN }}
32+
publish_dir: ./public

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,3 @@ Icon
9393
Network Trash Folder
9494
Temporary Items
9595
.apdisk
96-
97-
98-
src/graphql/api.ts
99-
src/graphql/introspection-result.ts

docker-compose.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.6"
1+
version: '3.6'
22
services:
33
postgres:
44
image: postgres:12
@@ -10,9 +10,9 @@ services:
1010
graphql-engine:
1111
image: hasura/graphql-engine:v2.0.10
1212
ports:
13-
- "8080:8080"
13+
- '8080:8080'
1414
depends_on:
15-
- "postgres"
15+
- 'postgres'
1616
restart: always
1717
environment:
1818
## postgres database to store Hasura metadata
@@ -22,10 +22,11 @@ services:
2222
## link heroku environment
2323
DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
2424
## enable the console served by server
25-
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
25+
HASURA_GRAPHQL_ENABLE_CONSOLE: 'true' # set to "false" to disable console
2626
## enable debugging mode. It is recommended to disable this in production
27-
HASURA_GRAPHQL_DEV_MODE: "true"
27+
HASURA_GRAPHQL_DEV_MODE: 'true'
2828
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
29+
HASURA_GRAPHQL_CORS_DOMAIN: 'http://localhost:3035'
2930
## uncomment next line to set an admin secret
3031
# HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
3132
volumes:

src/App.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React from 'react'
2+
import { ApolloProvider } from '@apollo/client'
23

34
import { Routes } from './routes'
45

5-
export const App = () => <Routes />
6+
import { client } from 'apolloClient'
7+
8+
export const App = () => (
9+
<ApolloProvider client={client}>
10+
<Routes />
11+
</ApolloProvider>
12+
)

src/apolloClient.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ApolloClient, InMemoryCache } from '@apollo/client'
2+
3+
import result from './graphql/introspection-result'
4+
5+
// Hasura Graphql endpoint
6+
const uri = 'http://localhost:8080/v1/graphql'
7+
const cache = new InMemoryCache(result)
8+
9+
export const client = new ApolloClient({
10+
uri,
11+
cache,
12+
})

src/components/Todos/index.tsx

+25-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { List, Typography, Space } from 'antd'
2+
import { List, Typography, Space, Card, Button, Divider } from 'antd'
33
import { CheckCircleTwoTone } from '@ant-design/icons'
44

55
type Todo = {
@@ -10,28 +10,32 @@ type Todo = {
1010

1111
type Props = {
1212
isLoading?: boolean
13-
todos: Todo[]
13+
todos?: Todo[]
14+
getContent?: () => void
1415
}
1516

16-
export const Todos: React.VFC<Props> = ({ todos, isLoading }) => {
17+
export const Todos: React.VFC<Props> = ({ todos, isLoading, getContent }) => {
18+
console.log(isLoading, new Date())
1719
return (
18-
<List
19-
size="large"
20-
loading={isLoading}
21-
dataSource={todos}
22-
renderItem={({ id, contents, finished }) => (
23-
<List.Item key={id}>
24-
<Typography.Title>
25-
<Space>
26-
<CheckCircleTwoTone
27-
twoToneColor={finished ? '#52c41a' : '#e3e3e3'}
28-
/>
29-
{contents}
30-
</Space>
31-
</Typography.Title>
32-
{/* <Typography.Title level={5}>{contents}</Typography.Title> */}
33-
</List.Item>
34-
)}
35-
/>
20+
<Card title="TODO List" style={{ margin: '5%' }}>
21+
<Button onClick={getContent}>データを取る</Button>
22+
<Divider />
23+
<List
24+
loading={isLoading}
25+
dataSource={todos}
26+
renderItem={({ id, contents, finished }) => (
27+
<List.Item key={id}>
28+
<Typography.Title level={3}>
29+
<Space>
30+
<CheckCircleTwoTone
31+
twoToneColor={finished ? '#52c41a' : '#e3e3e3'}
32+
/>
33+
{contents}
34+
</Space>
35+
</Typography.Title>
36+
</List.Item>
37+
)}
38+
/>
39+
</Card>
3640
)
3741
}

src/components/story/index.stories.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import { Todos } from '../Todos'
66
const todos = [
77
{
88
id: 1,
9-
contents: 'should do',
10-
finished: false,
9+
contents: '宇宙空間に行く',
10+
finished: true,
1111
},
1212
{
1313
id: 2,
14-
contents: 'done is better',
15-
finished: true,
14+
contents: '月旅行に行く',
15+
finished: false,
16+
},
17+
{
18+
id: 3,
19+
contents: '本を書く',
20+
finished: false,
1621
},
1722
]
1823

src/container/Home/index.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react'
2+
import { Card, Typography } from 'antd'
3+
import styled from 'styled-components'
4+
// import { useHistory } from 'react-router'
5+
6+
const Wrapper = styled.div`
7+
margin: 40px;
8+
`
9+
10+
const policies = [
11+
'cache-first',
12+
'network-only',
13+
'cache-and-network',
14+
'cache-only',
15+
'no-cache',
16+
'standby',
17+
]
18+
19+
export const HomeContainer = () => {
20+
return (
21+
<Wrapper>
22+
<Card title="Hello">
23+
<h1>Here is Home</h1>
24+
<ul>
25+
{policies.map((policy) => (
26+
<li key={policy}>
27+
<Typography.Link href={`/${policy}`}>{policy}</Typography.Link>
28+
</li>
29+
))}
30+
</ul>
31+
</Card>
32+
</Wrapper>
33+
)
34+
}

src/container/Todos/index.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { useCallback } from 'react'
2+
import { WatchQueryFetchPolicy } from '@apollo/client'
3+
import { useParams } from 'react-router'
4+
5+
import { Todos } from 'components/Todos'
6+
import { useTodosLazyQuery } from 'graphql/api'
7+
8+
export const TodosContainer: React.FC = () => {
9+
const { fetchPolicy = 'network-only' } = useParams<{
10+
fetchPolicy: WatchQueryFetchPolicy
11+
}>()
12+
13+
const [getTodo, { data, loading }] = useTodosLazyQuery({
14+
fetchPolicy: fetchPolicy as WatchQueryFetchPolicy,
15+
})
16+
const getContent = useCallback(() => getTodo(), [getTodo])
17+
return (
18+
<Todos todos={data?.todos} isLoading={loading} getContent={getContent} />
19+
)
20+
}

0 commit comments

Comments
 (0)