Update docker compose file

* Add token in global state
This commit is contained in:
DefectingCat
2022-02-10 19:32:59 +08:00
parent 5e6efb9976
commit 611f2112b8
2 changed files with 52 additions and 0 deletions

36
docker-compose.yml Normal file
View File

@ -0,0 +1,36 @@
version: '3.8'
services:
mysql:
container_name: mysql
image: mysql
# restart: always
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3309:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
networks:
- "front"
blog:
container_name: blog
build:
context: .
network: defectingcatgithubio_front
ports:
- "3000:3000"
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
depends_on:
- "mysql"
networks:
- "front"
networks:
front:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "true"

View File

@ -4,6 +4,7 @@ export enum ActionKind {
SETQUERY = 'SETQUERY',
SETPATH = 'SETPATH',
SETTHEME = 'SETTHEME',
SETTOKEN = 'SETTOEKN',
}
type ReducerAction = {
@ -27,12 +28,18 @@ type State = {
* Use document.documentElement.classList
*/
isDark: boolean;
/**
* User token, if exist that's mean user logined.
*/
token: string | null;
};
const initialState: State = {
searchQuery: '',
backPath: '',
isDark: false,
token: null,
};
const reducer = (state: State, action: ReducerAction): State => {
@ -47,6 +54,11 @@ const reducer = (state: State, action: ReducerAction): State => {
...state,
isDark: document.documentElement.classList.contains('dark'),
};
case ActionKind.SETTOKEN:
return {
...state,
token: window.localStorage.getItem('token'),
};
default:
throw new Error();
}
@ -68,6 +80,10 @@ const RUAStore: FC = ({ children }) => {
type: ActionKind.SETTHEME,
payload: '',
});
dispatch({
type: ActionKind.SETTOKEN,
payload: '',
});
}, []);
return (