1- import React from 'react' ;
2- // Import controllers
3- import collectionsController from '../../../../controllers/collectionsController'
4- // Import MUI components
5- import DialogTitle from '@mui/material/DialogTitle' ;
6- import Dialog from '@mui/material/Dialog' ;
7- import List from '@mui/material/List' ;
8- import ListItem from '@mui/material/ListItem' ;
9- import ListItemText from '@mui/material/ListItemText' ;
10- import ListItemButton from '@mui/material/ListItemButton' ;
11-
12-
13- // export interface SimpleDialogProps {
14- // open: boolean;
15- // selectedValue: string;
16- // onClose: (value: string) => void;
17- // }
18-
19- export default function ExportToGithubDialog ( { allUserRepos, workspace, selectedRepo, open, onClose} ) {
20- // const { onClose, selectedValue, open } = props;
21-
22- const handleClose = ( ) => {
23- onClose ( selectedRepo ) ;
24- } ;
25-
26- const handleListItemClick = ( value : string ) => {
27- onClose ( value ) ;
28- } ;
29-
30- const handleExportToRepo = ( repo ) => {
31- console . log ( 'need to export this specific file to this clicked-on repo.' )
32- console . log ( 'workspace to export:' , workspace )
33- console . log ( 'repo metadata:' , repo . repository )
34- collectionsController . exportToGithub ( workspace . id , repo . repository . name , repo . sha )
35- //
36- }
37-
38- console . log (
39- 'all user repos:' , allUserRepos
40- )
41- const repoListItems = [ ]
42- for ( let repo of allUserRepos ) {
43- // console.log('sha', repo.sha);
44- repoListItems . push (
45- < ListItemButton
46- key = { repo . repository . id }
47- onClick = { ( ) => handleExportToRepo ( repo ) }
48- >
49- < ListItem >
50- < ListItemText primary = { repo . repository . full_name } />
51- </ ListItem >
52- </ ListItemButton >
53- )
54- }
55-
56-
57- return (
58- < Dialog onClose = { handleClose } open = { open } >
59- < DialogTitle > Select a repository to export to.</ DialogTitle >
60- < List sx = { { pt : 0 } } >
61- { repoListItems }
62- { /* <ListItem autoFocus button onClick={() => handleListItemClick}>
63- <ListItemText primary="repo" />
64- </ListItem > */ }
65- </ List >
66- </ Dialog >
67- ) ;
68- }
1+ import React from 'react' ;
2+ // Import controllers
3+ import collectionsController from '../../../../controllers/collectionsController'
4+ // Import MUI components
5+ import DialogTitle from '@mui/material/DialogTitle' ;
6+ import Dialog from '@mui/material/Dialog' ;
7+ import List from '@mui/material/List' ;
8+ import ListItem from '@mui/material/ListItem' ;
9+ import ListItemText from '@mui/material/ListItemText' ;
10+ import ListItemButton from '@mui/material/ListItemButton' ;
11+ // Database handling
12+ import db from '../../../../db' ;
13+ import { useLiveQuery } from 'dexie-react-hooks' ;
14+
15+
16+ // export interface SimpleDialogProps {
17+ // open: boolean;
18+ // selectedValue: string;
19+ // onClose: (value: string) => void;
20+ // }
21+
22+ export default function ExportToGithubDialog ( { allUserRepos, workspace, selectedRepo, open, onClose} ) {
23+ let files = useLiveQuery ( ( ) => db . files . toArray ( ) ) ;
24+ let repos = useLiveQuery ( ( ) => db . repos . toArray ( ) ) ;
25+
26+ // db.table('repo')
27+ // .where('name')
28+ // .equalsIgnoreCase(name)
29+ // .first((foundCollection: boolean) => !!foundCollection)
30+ // .then((found: boolean) => resolve(found))
31+ // .catch((error: Record<string, undefined>) => {
32+ // console.error(error.stack || error);
33+ // reject(error);
34+ // });
35+
36+ const handleClose = ( ) => {
37+ onClose ( selectedRepo ) ;
38+ } ;
39+
40+ const handleListItemClick = ( value : string ) => {
41+ onClose ( value ) ;
42+ } ;
43+
44+ const handleExportToRepo = ( repo ) => {
45+ console . log ( 'need to export this specific file to this clicked-on repo.' )
46+ console . log ( 'workspace to export:' , workspace )
47+ console . log ( 'repo metadata:' , repo . repository )
48+ // grab sha off of current workspace
49+ let sha = '' ;
50+ for ( let file of files ) {
51+ if ( file . repository . full_name === repo . full_name ) {
52+ sha = file . sha ;
53+ }
54+ }
55+ // db.table('files')
56+ // .where((workspace) => {
57+
58+ // })
59+
60+
61+
62+ collectionsController . exportToGithub ( workspace . id , repo . name , sha )
63+ }
64+
65+ const repoListItems = [ ]
66+
67+ if ( repos !== undefined ) {
68+ console . log ( repos )
69+ for ( let repo of repos ) {
70+ repoListItems . push (
71+ < ListItemButton
72+ key = { repo . id }
73+ onClick = { ( ) => handleExportToRepo ( repo ) }
74+ >
75+ < ListItem >
76+ < ListItemText primary = { repo . full_name } />
77+ </ ListItem >
78+ </ ListItemButton >
79+ )
80+ }
81+ }
82+
83+
84+ return (
85+ < Dialog onClose = { handleClose } open = { open } >
86+ < DialogTitle > Select a repository to export to.</ DialogTitle >
87+ < List sx = { { pt : 0 } } >
88+ { repoListItems }
89+ { /* <ListItem autoFocus button onClick={() => handleListItemClick}>
90+ <ListItemText primary="repo" />
91+ </ListItem > */ }
92+ </ List >
93+ </ Dialog >
94+ ) ;
95+ }
0 commit comments