From eb6523f9c0a931ae94faaa2f1d83ad0cc5c3e12b Mon Sep 17 00:00:00 2001 From: monoid Date: Wed, 20 Jan 2021 14:27:14 +0900 Subject: [PATCH] fix duplicated keyerror --- src/client/page/difference.tsx | 65 ++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/src/client/page/difference.tsx b/src/client/page/difference.tsx index 4fdeb73..e3dc99d 100644 --- a/src/client/page/difference.tsx +++ b/src/client/page/difference.tsx @@ -15,32 +15,48 @@ const useStyles = makeStyles((theme:Theme)=>({ 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 ( + {x.type} + {x.value.map(y=>( + + + {y.path} + + ))} + ); +} export function DifferencePage(){ const ctx = useContext(UserContext); const classes = useStyles(); const [diffList,setDiffList] = useState< - {type:string,value:{path:string,type:string}[]}[] + FileDifference[] >([]); const doLoad = async ()=>{ const list = await fetch('/api/diff/list'); if(list.ok){ - const inner = await list.json(); - setDiffList(inner); + const inner = await list.json(); + setDiffList(inner); } else{ //setDiffList([]); } }; - useEffect( - ()=>{ - doLoad(); - const i = setInterval(doLoad,5000); - return ()=>{ - clearInterval(i); - } - },[] - ) const Commit = async(x:{type:string,path:string})=>{ const res = await fetch('/api/diff/commit',{ method:'POST', @@ -54,19 +70,22 @@ export function DifferencePage(){ doLoad(); } } + useEffect( + ()=>{ + doLoad(); + const i = setInterval(doLoad,5000); + return ()=>{ + clearInterval(i); + } + },[] + ) const menu = CommonMenuList(); - (ctx.username == "admin") return ( - {(ctx.username == "admin") ? (diffList.map(x=> - {x.type} - - {x.value.map(y=>( - <> - - {y.path} - ))} - - )):(Not Allowed : please login as an admin) + {(ctx.username == "admin") ? (
+ {(diffList.map(x=> + ))} +
) + :(Not Allowed : please login as an admin) }
)