Store backups in server state

This commit is contained in:
Dane Everitt 2020-04-06 22:25:54 -07:00
parent f9878d842c
commit 2eb6ab4d63
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 75 additions and 23 deletions

View file

@ -15,10 +15,10 @@ import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import useFlash from '@/plugins/useFlash';
import { httpErrorToHuman } from '@/api/http';
import useWebsocketEvent from '@/plugins/useWebsocketEvent';
import { ServerContext } from '@/state/server';
interface Props {
backup: ServerBackup;
onBackupUpdated: (backup: ServerBackup) => void;
className?: string;
}
@ -34,16 +34,18 @@ const DownloadModal = ({ checksum, ...props }: RequiredModalProps & { checksum:
</Modal>
);
export default ({ backup, onBackupUpdated, className }: Props) => {
export default ({ backup, className }: Props) => {
const { uuid } = useServer();
const { addError, clearFlashes } = useFlash();
const [ loading, setLoading ] = useState(false);
const [ visible, setVisible ] = useState(false);
const appendBackup = ServerContext.useStoreActions(actions => actions.backups.appendBackup);
useWebsocketEvent(`backup completed:${backup.uuid}`, data => {
try {
const parsed = JSON.parse(data);
onBackupUpdated({
appendBackup({
...backup,
sha256Hash: parsed.sha256_hash || '',
bytes: parsed.file_size || 0,