fix duplicated keyerror
This commit is contained in:
parent
50ce70435a
commit
eb6523f9c0
@ -15,12 +15,37 @@ const useStyles = makeStyles((theme:Theme)=>({
|
|||||||
marginLeft: theme.spacing(2)
|
marginLeft: theme.spacing(2)
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
type FileDifference = {
|
||||||
|
type:string,
|
||||||
|
value:{
|
||||||
|
type:string,
|
||||||
|
path:string,
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function TypeDifference(prop:{
|
||||||
|
content:FileDifference,
|
||||||
|
onCommit:(v:{type:string,path:string})=>void
|
||||||
|
}){
|
||||||
|
const classes = useStyles();
|
||||||
|
const x = prop.content;
|
||||||
|
return (<Paper className={classes.paper}>
|
||||||
|
<Typography variant='h3' className={classes.contentTitle}>{x.type}</Typography>
|
||||||
|
{x.value.map(y=>(
|
||||||
|
<Box className={classes.commitable} key={y.path}>
|
||||||
|
<Button onClick={()=>prop.onCommit(y)}>Commit</Button>
|
||||||
|
<Typography variant='h5'>{y.path}</Typography>
|
||||||
|
</Box>
|
||||||
|
))}
|
||||||
|
</Paper>);
|
||||||
|
}
|
||||||
|
|
||||||
export function DifferencePage(){
|
export function DifferencePage(){
|
||||||
const ctx = useContext(UserContext);
|
const ctx = useContext(UserContext);
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [diffList,setDiffList] = useState<
|
const [diffList,setDiffList] = useState<
|
||||||
{type:string,value:{path:string,type:string}[]}[]
|
FileDifference[]
|
||||||
>([]);
|
>([]);
|
||||||
const doLoad = async ()=>{
|
const doLoad = async ()=>{
|
||||||
const list = await fetch('/api/diff/list');
|
const list = await fetch('/api/diff/list');
|
||||||
@ -32,15 +57,6 @@ export function DifferencePage(){
|
|||||||
//setDiffList([]);
|
//setDiffList([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
useEffect(
|
|
||||||
()=>{
|
|
||||||
doLoad();
|
|
||||||
const i = setInterval(doLoad,5000);
|
|
||||||
return ()=>{
|
|
||||||
clearInterval(i);
|
|
||||||
}
|
|
||||||
},[]
|
|
||||||
)
|
|
||||||
const Commit = async(x:{type:string,path:string})=>{
|
const Commit = async(x:{type:string,path:string})=>{
|
||||||
const res = await fetch('/api/diff/commit',{
|
const res = await fetch('/api/diff/commit',{
|
||||||
method:'POST',
|
method:'POST',
|
||||||
@ -54,19 +70,22 @@ export function DifferencePage(){
|
|||||||
doLoad();
|
doLoad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
useEffect(
|
||||||
|
()=>{
|
||||||
|
doLoad();
|
||||||
|
const i = setInterval(doLoad,5000);
|
||||||
|
return ()=>{
|
||||||
|
clearInterval(i);
|
||||||
|
}
|
||||||
|
},[]
|
||||||
|
)
|
||||||
const menu = CommonMenuList();
|
const menu = CommonMenuList();
|
||||||
(ctx.username == "admin")
|
|
||||||
return (<Headline menu={menu}>
|
return (<Headline menu={menu}>
|
||||||
{(ctx.username == "admin") ? (diffList.map(x=><Paper key={x.type} className={classes.paper}>
|
{(ctx.username == "admin") ? (<div>
|
||||||
<Typography variant='h3' className={classes.contentTitle}>{x.type}</Typography>
|
{(diffList.map(x=>
|
||||||
<Box className={classes.commitable}>
|
<TypeDifference key={x.type} content={x} onCommit={Commit}/>))}
|
||||||
{x.value.map(y=>(
|
</div>)
|
||||||
<>
|
:(<Typography variant='h2'>Not Allowed : please login as an admin</Typography>)
|
||||||
<Button key={`button_${y.path}`} onClick={()=>Commit(y)}>Commit</Button>
|
|
||||||
<Typography key={`typography_${y.path}`} variant='h5'>{y.path}</Typography>
|
|
||||||
</>))}
|
|
||||||
</Box>
|
|
||||||
</Paper>)):(<Typography variant='h2'>Not Allowed : please login as an admin</Typography>)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</Headline>)
|
</Headline>)
|
||||||
|
Loading…
Reference in New Issue
Block a user