use one Archive instance for state.archive

This commit is contained in:
Danny Coates 2018-12-21 10:27:46 -08:00
parent 989137342b
commit c585c34c01
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
6 changed files with 14 additions and 13 deletions

View File

@ -68,4 +68,8 @@ export default class Archive {
this.files.splice(index, 1); this.files.splice(index, 1);
} }
} }
clear() {
this.files = [];
}
} }

View File

@ -3,7 +3,6 @@ import FileSender from './fileSender';
import FileReceiver from './fileReceiver'; import FileReceiver from './fileReceiver';
import { copyToClipboard, delay, openLinksInNewTab, percent } from './utils'; import { copyToClipboard, delay, openLinksInNewTab, percent } from './utils';
import * as metrics from './metrics'; import * as metrics from './metrics';
import Archive from './archive';
import { bytes } from './utils'; import { bytes } from './utils';
import okDialog from './ui/okDialog'; import okDialog from './ui/okDialog';
import copyDialog from './ui/copyDialog'; import copyDialog from './ui/copyDialog';
@ -66,9 +65,6 @@ export default function(state, emitter) {
emitter.on('removeUpload', file => { emitter.on('removeUpload', file => {
state.archive.remove(file); state.archive.remove(file);
if (state.archive.numFiles === 0) {
state.archive = null;
}
render(); render();
}); });
@ -99,7 +95,6 @@ export default function(state, emitter) {
return; return;
} }
const maxSize = state.user.maxSize; const maxSize = state.user.maxSize;
state.archive = state.archive || new Archive();
try { try {
state.archive.addFiles(files, maxSize); state.archive.addFiles(files, maxSize);
} catch (e) { } catch (e) {
@ -109,15 +104,11 @@ export default function(state, emitter) {
count: LIMITS.MAX_FILES_PER_ARCHIVE count: LIMITS.MAX_FILES_PER_ARCHIVE
}) })
); );
if (state.archive.numFiles === 0) {
state.archive = null;
}
} }
render(); render();
}); });
emitter.on('upload', async ({ type, dlimit, password }) => { emitter.on('upload', async ({ type, dlimit, password }) => {
if (!state.archive) return;
if (state.storage.files.length >= LIMITS.MAX_ARCHIVES_PER_USER) { if (state.storage.files.length >= LIMITS.MAX_ARCHIVES_PER_USER) {
state.modal = okDialog( state.modal = okDialog(
state.translate('tooManyArchives', { state.translate('tooManyArchives', {
@ -171,12 +162,12 @@ export default function(state, emitter) {
emitter.emit('pushState', '/error'); emitter.emit('pushState', '/error');
} }
} finally { } finally {
await state.user.syncFileList();
openLinksInNewTab(links, false); openLinksInNewTab(links, false);
state.archive = null; state.archive.clear();
state.password = ''; state.password = '';
state.uploading = false; state.uploading = false;
state.transfer = null; state.transfer = null;
await state.user.syncFileList();
render(); render();
} }
}); });

View File

@ -16,6 +16,7 @@ import Raven from 'raven-js';
import './main.css'; import './main.css';
import User from './user'; import User from './user';
import { getTranslator } from './locale'; import { getTranslator } from './locale';
import Archive from './archive';
if (navigator.doNotTrack !== '1' && window.RAVEN_CONFIG) { if (navigator.doNotTrack !== '1' && window.RAVEN_CONFIG) {
Raven.config(window.SENTRY_ID, window.RAVEN_CONFIG).install(); Raven.config(window.SENTRY_ID, window.RAVEN_CONFIG).install();
@ -37,6 +38,7 @@ if (process.env.NODE_ENV === 'production') {
const translate = await getTranslator(LOCALE); const translate = await getTranslator(LOCALE);
window.initialState = { window.initialState = {
archive: new Archive(),
capabilities, capabilities,
translate, translate,
storage, storage,

View File

@ -345,6 +345,7 @@ module.exports.empty = function(state, emit) {
/> />
<label <label
for="file-upload" for="file-upload"
role="button"
class="rounded bg-blue hover\:bg-blue-dark focus\:bg-blue-darker cursor-pointer text-center text-white py-2 px-6 h-12 mt-4 flex flex-no-shrink items-center justify-center font-semibold" class="rounded bg-blue hover\:bg-blue-dark focus\:bg-blue-darker cursor-pointer text-center text-white py-2 px-6 h-12 mt-4 flex flex-no-shrink items-center justify-center font-semibold"
title="${state.translate('addFilesButton')}" title="${state.translate('addFilesButton')}"
> >

View File

@ -11,14 +11,14 @@ module.exports = function(state, emit) {
let left = ''; let left = '';
if (state.uploading) { if (state.uploading) {
left = archiveTile.uploading(state, emit); left = archiveTile.uploading(state, emit);
} else if (state.archive) { } else if (state.archive.numFiles > 0) {
left = archiveTile.wip(state, emit); left = archiveTile.wip(state, emit);
} else { } else {
left = archiveTile.empty(state, emit); left = archiveTile.empty(state, emit);
} }
archives.reverse(); archives.reverse();
const right = const right =
archives.length < 1 archives.length === 0
? intro(state) ? intro(state)
: list( : list(
archives, archives,

View File

@ -16,6 +16,9 @@ module.exports = async function(req) {
} }
} }
return { return {
archive: {
numFiles: 0
},
locale, locale,
capabilities: { account: false }, capabilities: { account: false },
translate: getTranslator(locale), translate: getTranslator(locale),