sync status button
This commit is contained in:
parent
44033eb4fd
commit
cd996a0b49
|
@ -1,15 +1,31 @@
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Button, Dialog, IconButton } from '@mui/material';
|
import { Button, CircularProgress, Dialog, IconButton } from '@mui/material';
|
||||||
import watchService, { WatchMapping } from 'services/watchService';
|
import watchService, { WatchMapping } from 'services/watchService';
|
||||||
import { MdDelete } from 'react-icons/md';
|
import { MdDelete } from 'react-icons/md';
|
||||||
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
|
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
|
||||||
import Close from '@mui/icons-material/Close';
|
import Close from '@mui/icons-material/Close';
|
||||||
import { SpaceBetweenFlex } from 'components/Container';
|
import { SpaceBetweenFlex } from 'components/Container';
|
||||||
|
|
||||||
function WatchModal({ watchModalView, setWatchModalView }) {
|
function WatchModal({
|
||||||
|
watchModalView,
|
||||||
|
setWatchModalView,
|
||||||
|
}: {
|
||||||
|
watchModalView: boolean;
|
||||||
|
setWatchModalView: (watchModalView: boolean) => void;
|
||||||
|
}) {
|
||||||
const [mappings, setMappings] = useState<WatchMapping[]>([]);
|
const [mappings, setMappings] = useState<WatchMapping[]>([]);
|
||||||
const [shouldUpdateMappings, setShouldUpdateMappings] = useState(true);
|
const [shouldUpdateMappings, setShouldUpdateMappings] = useState(true);
|
||||||
const [inputFolderPath, setInputFolderPath] = useState('');
|
const [inputFolderPath, setInputFolderPath] = useState('');
|
||||||
|
const [isSyncing, setIsSyncing] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (watchModalView) {
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
setIsSyncing(watchService.isEventRunning);
|
||||||
|
}, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}
|
||||||
|
}, [watchModalView]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (shouldUpdateMappings) {
|
if (shouldUpdateMappings) {
|
||||||
|
@ -39,6 +55,12 @@ function WatchModal({ watchModalView, setWatchModalView }) {
|
||||||
setShouldUpdateMappings(true);
|
setShouldUpdateMappings(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSyncProgressClick = () => {
|
||||||
|
if (watchService.isUploadRunning) {
|
||||||
|
// show progress view
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setWatchModalView(false);
|
setWatchModalView(false);
|
||||||
};
|
};
|
||||||
|
@ -103,17 +125,26 @@ function WatchModal({ watchModalView, setWatchModalView }) {
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<SpaceBetweenFlex
|
||||||
style={{
|
sx={{
|
||||||
|
marginTop: '20px',
|
||||||
borderTop: '1px solid #e6e6e6',
|
borderTop: '1px solid #e6e6e6',
|
||||||
paddingTop: '12px',
|
paddingTop: '12px',
|
||||||
marginTop: '20px',
|
}}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
marginBottom: '8px',
|
marginBottom: '8px',
|
||||||
fontSize: '28px',
|
fontSize: '28px',
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
}}>
|
}}>
|
||||||
Current Watch Mappings
|
Current Watch Mappings
|
||||||
</div>
|
</div>
|
||||||
|
{isSyncing && (
|
||||||
|
<IconButton onClick={handleSyncProgressClick}>
|
||||||
|
<CircularProgress size={24} />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
</SpaceBetweenFlex>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
marginTop: '12px',
|
marginTop: '12px',
|
||||||
|
|
|
@ -27,10 +27,12 @@ class WatchService {
|
||||||
allElectronAPIsExist: boolean = false;
|
allElectronAPIsExist: boolean = false;
|
||||||
eventQueue: EventQueueType[] = [];
|
eventQueue: EventQueueType[] = [];
|
||||||
isEventRunning: boolean = false;
|
isEventRunning: boolean = false;
|
||||||
|
isUploadRunning: boolean = false;
|
||||||
pathToIDMap = new Map<string, number>();
|
pathToIDMap = new Map<string, number>();
|
||||||
setElectronFiles: (files: ElectronFile[]) => void;
|
setElectronFiles: (files: ElectronFile[]) => void;
|
||||||
setCollectionName: (collectionName: string) => void;
|
setCollectionName: (collectionName: string) => void;
|
||||||
syncWithRemote: () => void;
|
syncWithRemote: () => void;
|
||||||
|
showProgressView: () => void;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs'];
|
this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs'];
|
||||||
|
@ -170,6 +172,7 @@ class WatchService {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isEventRunning = true;
|
this.isEventRunning = true;
|
||||||
|
this.isUploadRunning = true;
|
||||||
|
|
||||||
this.batchNextEvent();
|
this.batchNextEvent();
|
||||||
|
|
||||||
|
@ -282,6 +285,7 @@ class WatchService {
|
||||||
|
|
||||||
this.eventQueue.shift();
|
this.eventQueue.shift();
|
||||||
this.isEventRunning = false;
|
this.isEventRunning = false;
|
||||||
|
this.isUploadRunning = false;
|
||||||
this.runNextEvent();
|
this.runNextEvent();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError(e, 'error while running all file uploads done');
|
logError(e, 'error while running all file uploads done');
|
||||||
|
|
Loading…
Reference in a new issue