@@ -872,6 +872,89 @@ function SidebarTest() {
872872 ) ;
873873}
874874
875+ function ConfigButton ( ) {
876+ let reponame = useSelector ( ( state ) => state . repo . reponame ) ;
877+ const dispatch = useDispatch ( ) ;
878+ // let username = useSelector((state) => state.repo.username);
879+ const { data, loading, error } = useQuery ( gql `
880+ query RepoConfig {
881+ repoConfig(name: "${ reponame } ")
882+ }
883+ ` ) ;
884+ const [ updateRepoConfig , { } ] = useMutation (
885+ gql `
886+ mutation UpdateRepoConfig($reponame: String, $config: String) {
887+ updateRepoConfig(name: $reponame, config: $config)
888+ }
889+ ` ,
890+ { refetchQueries : [ "RepoConfig" ] }
891+ ) ;
892+ useEffect ( ( ) => {
893+ console . log ( data ) ;
894+ if ( data ) {
895+ dispatch ( repoSlice . actions . setRepoConfig ( JSON . parse ( data . repoConfig ) ) ) ;
896+ }
897+ } , [ data ] ) ;
898+ const repoConfig = useSelector ( ( state ) => state . repo . repoConfig ) ;
899+ // console.log("repoConfig", repoConfig);
900+ // console.log("ConfigButton", data);
901+ // const [open, setOpen] = React.useState(false);
902+ // const handleOpen = () => setOpen(true);
903+ // const handleClose = () => setOpen(false);
904+ const { isOpen, onOpen, onClose } = useDisclosure ( ) ;
905+ return (
906+ < Box >
907+ < Button
908+ onClick = { ( ) => {
909+ // 1. show a new interface
910+ // setOpen(true);
911+ onOpen ( ) ;
912+ // 2. do the config
913+ // 3. update the config
914+ } }
915+ >
916+ Config
917+ </ Button >
918+ < Modal isOpen = { isOpen } onClose = { onClose } size = "6xl" >
919+ < ModalOverlay />
920+
921+ < ModalContent >
922+ < ModalHeader > Config</ ModalHeader >
923+ < ModalCloseButton />
924+ < ModalBody h = { 50 } overflow = "scroll" >
925+ < Box >
926+ < Text > Double Click to Edit</ Text >
927+ < Switch
928+ defaultChecked = { repoConfig && repoConfig . doubleClickToEdit }
929+ onChange = { ( e ) => {
930+ // dispatch(repoSlice.actions.setDevMode(e.target.checked));
931+ updateRepoConfig ( {
932+ variables : {
933+ reponame,
934+ config : JSON . stringify ( {
935+ doubleClickToEdit : e . target . checked ,
936+ } ) ,
937+ } ,
938+ } ) ;
939+ } }
940+ > </ Switch >
941+ </ Box >
942+ </ ModalBody >
943+
944+ < ModalFooter >
945+ { /* <Button colorScheme="blue" mr={3} onClick={onClose}>
946+ Save
947+ </Button> */ }
948+ < Button colorScheme = "blue" mr = { 3 } onClick = { onClose } >
949+ Close
950+ </ Button >
951+ </ ModalFooter >
952+ </ ModalContent >
953+ </ Modal >
954+ </ Box >
955+ ) ;
956+ }
957+
875958export function Sidebar ( ) {
876959 return (
877960 < Box mx = { 2 } px = "1rem" boxShadow = "xl" rounded = "md" bg = "gray.200" >
@@ -898,6 +981,7 @@ export function Sidebar() {
898981 < ApplyAll />
899982 </ Box >
900983 < Divider my = { 2 } />
984+ < ConfigButton />
901985 </ Box >
902986 ) ;
903987}
0 commit comments