@@ -8,13 +8,15 @@ import {
88 useDiagram ,
99 useEnums ,
1010 useNotes ,
11+ useSaveState ,
1112 useTransform ,
1213 useTypes ,
1314} from "../../../hooks" ;
1415import { databases } from "../../../data/databases" ;
1516import { octokit } from "../../../data/octokit" ;
17+ import { MODAL , State } from "../../../data/constants" ;
1618
17- export default function Share ( { title } ) {
19+ export default function Share ( { title, setModal } ) {
1820 const { t } = useTranslation ( ) ;
1921 const { gistId, setGistId } = useContext ( IdContext ) ;
2022 const [ loading , setLoading ] = useState ( true ) ;
@@ -24,6 +26,7 @@ export default function Share({ title }) {
2426 const { types } = useTypes ( ) ;
2527 const { enums } = useEnums ( ) ;
2628 const { transform } = useTransform ( ) ;
29+ const { setSaveState } = useSaveState ( ) ;
2730 const url =
2831 window . location . origin + window . location . pathname + "?shareId=" + gistId ;
2932
@@ -51,6 +54,22 @@ export default function Share({ title }) {
5154 transform ,
5255 ] ) ;
5356
57+ const unshare = useCallback ( async ( ) => {
58+ try {
59+ await octokit . request ( `DELETE /gists/${ gistId } ` , {
60+ gist_id : gistId ,
61+ headers : {
62+ "X-GitHub-Api-Version" : "2022-11-28" ,
63+ } ,
64+ } ) ;
65+ setGistId ( "" ) ;
66+ setModal ( MODAL . NONE ) ;
67+ setSaveState ( State . SAVING ) ;
68+ } catch ( e ) {
69+ console . error ( e ) ;
70+ }
71+ } , [ gistId , setGistId , setModal , setSaveState ] ) ;
72+
5473 const updateGist = useCallback ( async ( ) => {
5574 setLoading ( true ) ;
5675 try {
@@ -136,17 +155,16 @@ export default function Share({ title }) {
136155 < div >
137156 < div className = "flex gap-3" >
138157 < Input value = { url } size = "large" />
139- < Button
140- size = "large"
141- theme = "solid"
142- icon = { < IconLink /> }
143- onClick = { copyLink }
144- >
158+ </ div >
159+ < div className = "text-xs mt-2" > { t ( "share_info" ) } </ div >
160+ < div className = "flex gap-2 mt-3" >
161+ < Button block onClick = { unshare } >
162+ { t ( "unshare" ) }
163+ </ Button >
164+ < Button block theme = "solid" icon = { < IconLink /> } onClick = { copyLink } >
145165 { t ( "copy_link" ) }
146166 </ Button >
147167 </ div >
148- < hr className = "opacity-20 mt-3 mb-1" />
149- < div className = "text-xs" > { t ( "share_info" ) } </ div >
150168 </ div >
151169 ) ;
152170}
0 commit comments