-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: use css to switch dark buttons * chore: remove types for classnames, remove console * feat: add default style for button group, add i18n in not found, add html bg * feat: init fetch * chore: add git attr for text eol * chore: add spelling and type check in husky * chore: add missing yarn cmd * chore: fix spell * chore: fix spell * chore: downgrade husky to ~3.1
- Loading branch information
Showing
31 changed files
with
376 additions
and
42 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 |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
"words": [ | ||
"vite", | ||
"testid", | ||
"svgr" | ||
"svgr", | ||
"deduping" | ||
], | ||
"flagWords": [], | ||
"ignorePaths": [ | ||
|
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 @@ | ||
* text eol=lf |
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,6 +1,6 @@ | ||
{ | ||
"hooks": { | ||
"pre-commit": "echo \"git commit trigger husky pre-commit hook\" && lint-staged", | ||
"pre-commit": "echo \"git commit trigger husky pre-commit hook\" && lint-staged && yarn test:spelling && tsc", | ||
"post-commit": "git update-index --again" | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"Post": { | ||
"title": "string", | ||
"views": "int", | ||
"published": "boolean", | ||
"createdAt": "date" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
import React, { FC } from 'react' | ||
import AppRouter from '@AppRouter' | ||
|
||
console.log('invoke CI') | ||
import { SWRConfig as SWRConfigProvider } from 'swr' | ||
import { get } from '@data' | ||
|
||
const App: FC = () => ( | ||
<div className="app-body"> | ||
<AppRouter /> | ||
</div> | ||
<SWRConfigProvider | ||
// https://swr.vercel.app/docs/global-configuration | ||
value={{ | ||
fetcher: get, | ||
shouldRetryOnError: false, | ||
revalidateOnFocus: false, | ||
}} | ||
> | ||
<div className="app-body"> | ||
<AppRouter /> | ||
</div> | ||
</SWRConfigProvider> | ||
) | ||
|
||
export default App |
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 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,3 @@ | ||
import React, { FC } from 'react' | ||
|
||
export const Post: FC = () => <div>Hello, World!</div> |
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 @@ | ||
export { Post } from './Post' |
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,2 +1,3 @@ | ||
export * from './Home' | ||
export * from './Landing' | ||
export { FooterButtonGroup } from './FooterButtonGroup' |
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,15 @@ | ||
import React, { FC } from 'react' | ||
import { usePost } from '@data' | ||
|
||
export const Post: FC = () => { | ||
const { data: post, loading, error } = usePost(1) | ||
|
||
return ( | ||
<div className="h-screen flex flex-col items-center justify-center"> | ||
{loading && <div>Loading...</div>} | ||
{/* usually error could be handle in axios like show a message, but feel free if you want to add error display when request error */} | ||
{error && <div>Error</div>} | ||
<div>{post?.title}</div> | ||
</div> | ||
) | ||
} |
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 @@ | ||
export { Post as PostOrganisms } from './Post' |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export { Landing } from './Landing' | ||
export { Landing as LandingOrganisms } from './Landing' |
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 +1,2 @@ | ||
export * from './Home' | ||
export * from './Landing' |
Empty file.
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,54 @@ | ||
import axios from 'axios' | ||
|
||
export const fetcher = axios.create({ | ||
// baseURL: 'https://mockend.com/wwwenjie/react-starter/', | ||
baseURL: 'https://jsonplaceholder.typicode.com/', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-type': 'application/json', | ||
}, | ||
}) | ||
|
||
const onRequestError = async (error: any) => { | ||
// logic when request error | ||
} | ||
|
||
const onResponseError = async (error: any) => { | ||
if (error?.response?.status) { | ||
await onResponseStatus(error.response.status) | ||
} | ||
|
||
// logic when response error | ||
} | ||
|
||
const onResponseStatus = async (status: number) => { | ||
const statusMapper = new Map<number, () => void>() | ||
.set(401, () => { | ||
// redirect to login or anything you want | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
.set(404, () => {}) | ||
|
||
const func = statusMapper.get(status) | ||
if (func) { | ||
await func() | ||
} | ||
} | ||
|
||
fetcher.interceptors.request.use( | ||
(config) => config, | ||
async (error) => { | ||
await onRequestError(error) | ||
return Promise.reject(error) | ||
}, | ||
) | ||
|
||
fetcher.interceptors.response.use( | ||
async (response) => response.data, | ||
async (error) => { | ||
await onResponseError(error) | ||
return Promise.reject(error) | ||
}, | ||
) | ||
|
||
export const { get, post, patch, delete: deleteFetch } = fetcher |
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,30 @@ | ||
import useSWR from 'swr' | ||
|
||
export type Post = { | ||
readonly title: string | ||
readonly views: number | ||
readonly published: boolean | ||
readonly createdAt: Date | ||
} | ||
|
||
export const usePosts = () => { | ||
const { data, error } = useSWR<readonly Post[]>('posts') | ||
|
||
return { | ||
data, | ||
loading: !error && !data, | ||
error, | ||
} | ||
} | ||
|
||
export const usePost = (postId: number) => { | ||
const { data, error } = useSWR<Post>(`posts/${postId}`, { | ||
dedupingInterval: 600, | ||
}) | ||
|
||
return { | ||
data, | ||
loading: !error && !data, | ||
error, | ||
} | ||
} |
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,2 @@ | ||
export * from './Fetcher' | ||
export * from './Post' |
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,5 +1,6 @@ | ||
{ | ||
"desc": "Opinionated React Starter Template", | ||
"learn": "Learn", | ||
"docs": "Docs" | ||
"docs": "Docs", | ||
"notFound": "Sorry, the page you visited does not exist." | ||
} |
Oops, something went wrong.
61b63f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: