Skip to content

Commit

Permalink
Improve UX when performing a long running operation #392
Browse files Browse the repository at this point in the history
  • Loading branch information
tnajdek committed Dec 14, 2024
1 parent ef85732 commit 26d5499
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 217 deletions.
11 changes: 1 addition & 10 deletions src/js/actions/current.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { exportItems, chunkedToggleTagsOnItems, chunkedAddToCollection, chunkedC
chunkedDeleteItems, chunkedMoveItemsToTrash, chunkedRecoverItemsFromTrash,
chunkedRemoveFromCollection, chunkedUpdateCollectionsTrash, chunkedDeleteCollections, createItem, createItemOfType, toggleModal, navigate } from '.';
import columnProperties from '../constants/column-properties';
import { BIBLIOGRAPHY, COLLECTION_SELECT, EXPORT, NEW_FILE, NEW_ITEM } from '../constants/modals';
import { BIBLIOGRAPHY, COLLECTION_SELECT, EXPORT, NEW_ITEM } from '../constants/modals';
import { TOGGLE_ADD, TOGGLE_REMOVE } from '../common/tags';

const currentDuplicateItem = () => {
Expand Down Expand Up @@ -34,14 +34,6 @@ const currentNewItemModal = () => {
}
}

const currentNewFileModal = () => {
return async (dispatch, getState) => {
const state = getState();
const { collectionKey } = state.current;
return await dispatch(toggleModal(NEW_FILE, true, { collectionKey }));
}
}

const currentCreateItemOfType = (itemType) => {
return async (dispatch, getState) => {
const state = getState();
Expand Down Expand Up @@ -278,7 +270,6 @@ export {
currentExportItems,
currentExportItemsModal,
currentGoToSubscribeUrl,
currentNewFileModal,
currentNewItemModal,
currentRecoverFromTrash,
currentRemoveColoredTags,
Expand Down
19 changes: 16 additions & 3 deletions src/js/actions/items-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,10 @@ const chunkedCopyToLibrary = (itemKeys, sourceLibraryKey, ...args) => {
const id = getUniqueId();

dispatch({
count: itemKeys.length,
id,
data: {
count: itemKeys.length,
},
kind: 'cross-library-copy-items',
libraryKey: sourceLibraryKey,
type: BEGIN_ONGOING,
Expand Down Expand Up @@ -1452,15 +1454,22 @@ const createAttachments = (filesData, { linkMode = 'imported_file', collection =
if (libraryKey === null) {
libraryKey = state.current.libraryKey;
}
const data = {
count: filesData.length,
collectionKey: collection,
libraryKey
};

dispatch({
count: filesData.length,
id,
data,
kind: 'upload',
libraryKey,
type: BEGIN_ONGOING,
});

let createdItems;

try {
const attachmentTemplate = await dispatch(
fetchItemTemplate('attachment', linkMode)
Expand All @@ -1474,7 +1483,7 @@ const createAttachments = (filesData, { linkMode = 'imported_file', collection =
title: fd.fileName,
}));

const createdItems = await dispatch(
createdItems = await dispatch(
createItems(attachmentItems, libraryKey)
);

Expand All @@ -1495,6 +1504,10 @@ const createAttachments = (filesData, { linkMode = 'imported_file', collection =
} finally {
dispatch({
id,
data: {
...data,
createdItemsKeys: createdItems?.length ? createdItems.map(i => i.key) : []
},
kind: 'upload',
libraryKey,
type: COMPLETE_ONGOING,
Expand Down
2 changes: 2 additions & 0 deletions src/js/component/item/actions/upload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const UploadAction = () => {
}, []);

const handleFileInputChange = useCallback(async ev => {
const target = ev.currentTarget; // persist, or it will be nullified after await
const filesData = await getFilesData(Array.from(ev.currentTarget.files));
target.value = ''; // clear the invisible input so that onChange is triggered even if the same file is selected again
dispatch(createAttachments(filesData, { collection: collectionKey }));
}, [collectionKey, dispatch]);

Expand Down
10 changes: 4 additions & 6 deletions src/js/component/modal-manager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ import AddItemsToCollectionsModal from './modal/add-items-to-collections';
import AddLinkedUrlTouchModal from './modal/add-linked-url-touch';
import BibliographyModal from './modal/bibliography';
import ExportModal from './modal/export';
import IdentifierPicker from './modal/identifier-picker';
import ItemsSortModal from './modal/items-sort';
import ManageTagsModal from './modal/manage-tags';
import MoveCollectionsModal from './modal/move-collections';
import NewCollectionModal from './modal/new-collection';
import NewFileModal from './modal/new-file';
import NewItemModal from './modal/new-item';
import RenameCollectionModal from './modal/rename-collection';
import SettingsModal from './modal/settings';
import StyleInstallerModal from './modal/style-installer';
import IdentifierPicker from './modal/identifier-picker';
import ManageTagsModal from './modal/manage-tags';

import { ADD_LINKED_URL_TOUCH, BIBLIOGRAPHY, COLLECTION_ADD, COLLECTION_RENAME, COLLECTION_SELECT,
EXPORT, IDENTIFIER_PICKER, MANAGE_TAGS, MOVE_COLLECTION, NEW_ITEM, SETTINGS, SORT_ITEMS,
STYLE_INSTALLER, ADD_BY_IDENTIFIER, NEW_FILE } from '../constants/modals';
STYLE_INSTALLER, ADD_BY_IDENTIFIER, } from '../constants/modals';

const lookup = {
[ADD_BY_IDENTIFIER]: AddByIdentifierModal,
Expand All @@ -33,11 +32,10 @@ const lookup = {
[IDENTIFIER_PICKER]: IdentifierPicker,
[MANAGE_TAGS]: ManageTagsModal,
[MOVE_COLLECTION]: MoveCollectionsModal,
[NEW_FILE]: NewFileModal,
[NEW_ITEM]: NewItemModal,
[SETTINGS]: SettingsModal,
[SORT_ITEMS]: ItemsSortModal,
[STYLE_INSTALLER]: StyleInstallerModal,
[SETTINGS]: SettingsModal,
};

const UNMOUNT_DELAY = 500; // to allow outro animatons (delay in ms)
Expand Down
153 changes: 0 additions & 153 deletions src/js/component/modal/new-file.jsx

This file was deleted.

Loading

0 comments on commit 26d5499

Please sign in to comment.