Compare commits
1 Commits
master
...
manage_cle
Author | SHA1 | Date |
---|---|---|
|
e046e0ac62 | 5 years ago |
3 changed files with 116 additions and 0 deletions
@ -0,0 +1,96 @@ |
|||||||
|
import React from 'react'; |
||||||
|
import * as serverApi from '../../api'; |
||||||
|
import { WindowState } from './Windows'; |
||||||
|
import { Box, Button, Dialog, DialogTitle, DialogContent, CircularProgress } from '@material-ui/core'; |
||||||
|
var _ = require('lodash'); |
||||||
|
|
||||||
|
export enum ClearDBState { |
||||||
|
None = 0, |
||||||
|
Confirming, |
||||||
|
Executing, |
||||||
|
} |
||||||
|
|
||||||
|
export interface ManageWindowState extends WindowState { |
||||||
|
clearDBState: ClearDBState, |
||||||
|
} |
||||||
|
|
||||||
|
export enum ManageWindowStateActions { |
||||||
|
SetClearDBState = "SetClearDBState", |
||||||
|
} |
||||||
|
|
||||||
|
export function ManageWindowReducer(state: ManageWindowState, action: any) { |
||||||
|
switch (action.type) { |
||||||
|
case ManageWindowStateActions.SetClearDBState: |
||||||
|
return { ...state, clearDBState: action.value } |
||||||
|
default: |
||||||
|
throw new Error("Unimplemented ManageWindow state update.") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
export interface IProps { |
||||||
|
state: ManageWindowState, |
||||||
|
dispatch: (action: any) => void, |
||||||
|
mainDispatch: (action: any) => void, |
||||||
|
} |
||||||
|
|
||||||
|
export default function ManageWindow(props: IProps) { |
||||||
|
const startClearDB = () => { |
||||||
|
props.dispatch({ |
||||||
|
type: ManageWindowStateActions.SetClearDBState, |
||||||
|
value: ClearDBState.Executing, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
return <> |
||||||
|
<Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> |
||||||
|
<Box |
||||||
|
m={1} |
||||||
|
mt={4} |
||||||
|
width="80%" |
||||||
|
> |
||||||
|
<Button |
||||||
|
variant="contained" color="secondary" |
||||||
|
onClick={() => props.dispatch({ |
||||||
|
type: ManageWindowStateActions.SetClearDBState, |
||||||
|
value: ClearDBState.Confirming |
||||||
|
})} |
||||||
|
>Clear database</Button> |
||||||
|
</Box> |
||||||
|
</Box> |
||||||
|
<Dialog |
||||||
|
open={props.state.clearDBState === ClearDBState.Confirming} |
||||||
|
> |
||||||
|
<DialogTitle>Are you sure?</DialogTitle> |
||||||
|
<DialogContent> |
||||||
|
<Box m={1}> |
||||||
|
Clearing the database cannot be undone. All music information will be lost. |
||||||
|
</Box> |
||||||
|
<Box m={1} display="flex" alignItems="center"> |
||||||
|
<Box m={1}> |
||||||
|
<Button |
||||||
|
variant="contained" color="secondary" |
||||||
|
onClick={startClearDB} |
||||||
|
>I'm sure</Button> |
||||||
|
</Box> |
||||||
|
<Box m={1}> |
||||||
|
<Button |
||||||
|
variant="outlined" |
||||||
|
onClick={() => props.dispatch({ |
||||||
|
type: ManageWindowStateActions.SetClearDBState, |
||||||
|
value: ClearDBState.None |
||||||
|
})} |
||||||
|
>Never mind</Button> |
||||||
|
</Box> |
||||||
|
</Box> |
||||||
|
</DialogContent> |
||||||
|
</Dialog> |
||||||
|
<Dialog |
||||||
|
open={props.state.clearDBState === ClearDBState.Executing} |
||||||
|
> |
||||||
|
<DialogTitle>Clearing Database</DialogTitle> |
||||||
|
<DialogContent> |
||||||
|
<CircularProgress /> |
||||||
|
</DialogContent> |
||||||
|
</Dialog> |
||||||
|
</> |
||||||
|
} |
Loading…
Reference in new issue