diff --git a/packages/user-interface/src/components/gallery-image.tsx b/packages/user-interface/src/components/gallery-image.tsx index c8577a9..3ab3dce 100644 --- a/packages/user-interface/src/components/gallery-image.tsx +++ b/packages/user-interface/src/components/gallery-image.tsx @@ -151,14 +151,14 @@ export function GalleryImage({ item, onClick, x, y, width, height }: IGalleryIma alignItems: "center", cursor: "pointer", }} - onClick={async event => { + onClick={event => { event.preventDefault(); event.stopPropagation(); if (item.selected) { - await removeFromMultipleSelection(item); + removeFromMultipleSelection(item); } else { - await addToMultipleSelection(item); + addToMultipleSelection(item); } }} > diff --git a/packages/user-interface/src/context/asset-database-source.tsx b/packages/user-interface/src/context/asset-database-source.tsx index 3e3a209..2a7a09a 100644 --- a/packages/user-interface/src/context/asset-database-source.tsx +++ b/packages/user-interface/src/context/asset-database-source.tsx @@ -45,7 +45,7 @@ export function AssetDatabaseProvider({ children }: IAssetDatabaseProviderProps) // // Adds an asset to the source. // - async function addAsset(asset: IGalleryItem): Promise { + function addAsset(asset: IGalleryItem): void { setAssets([ { ...asset, setIndex: 0 } ] .concat( @@ -108,7 +108,7 @@ export function AssetDatabaseProvider({ children }: IAssetDatabaseProviderProps) // // Updates an existing asset. // - async function updateAsset(assetIndex: number, partialAsset: Partial): Promise { + function updateAsset(assetIndex: number, partialAsset: Partial): void { const assetId = assets[assetIndex]._id; const updatedAsset = { ...assets[assetIndex], ...partialAsset }; @@ -160,10 +160,11 @@ export function AssetDatabaseProvider({ children }: IAssetDatabaseProviderProps) }); setAssets(_assets); } + // // Adds an array value to the asset. // - async function addArrayValue(assetIndex: number, field: string, value: any): Promise { + function addArrayValue(assetIndex: number, field: string, value: any): void { const assetId = assets[assetIndex]._id; const updatedAsset: any = { ...assets[assetIndex] }; if (updatedAsset[field] === undefined) { @@ -214,7 +215,7 @@ export function AssetDatabaseProvider({ children }: IAssetDatabaseProviderProps) // // Removes an array value from the asset. // - async function removeArrayValue(assetIndex: number, field: string, value: any): Promise { + function removeArrayValue(assetIndex: number, field: string, value: any): void { const assetId = assets[assetIndex]._id; const updatedAsset: any = { ...assets[assetIndex] }; if (updatedAsset[field] === undefined) { diff --git a/packages/user-interface/src/context/gallery-context.tsx b/packages/user-interface/src/context/gallery-context.tsx index c58464b..7ef4534 100644 --- a/packages/user-interface/src/context/gallery-context.tsx +++ b/packages/user-interface/src/context/gallery-context.tsx @@ -36,22 +36,22 @@ export interface IGalleryContext { // // Adds an item to the the gallery. // - addGalleryItem(galleryItem: IGalleryItem): Promise; + addGalleryItem(galleryItem: IGalleryItem): void; // // Updates an item in the gallery by index. // - updateGalleryItem(assetIndex: number, partialGalleryItem: Partial): Promise; + updateGalleryItem(assetIndex: number, partialGalleryItem: Partial): void; // // Adds an array value to the asset. // - addArrayValue(assetIndex: number, field: string, value: any): Promise; + addArrayValue(assetIndex: number, field: string, value: any): void; // // Removes an array value from the asset. // - removeArrayValue(assetIndex: number, field: string, value: any): Promise; + removeArrayValue(assetIndex: number, field: string, value: any): void; // // Checks if an asset is already uploaded. @@ -106,22 +106,22 @@ export interface IGalleryContext { // // Multiple selected gallery items. // - selectedItems: IGalleryItem[]; //fio: + selectedItems: IGalleryItem[]; // // Add the item to the multiple selection. // - addToMultipleSelection(item: IGalleryItem): Promise; + addToMultipleSelection(item: IGalleryItem): void; // // Remove the item from the multiple selection. // - removeFromMultipleSelection(item: IGalleryItem): Promise; + removeFromMultipleSelection(item: IGalleryItem): void; // // Clears the multiple selection. // - clearMultiSelection(): Promise; + clearMultiSelection(): void; // // The current search text. @@ -153,7 +153,7 @@ export interface IGalleryContextProviderProps { export function GalleryContextProvider({ sortFn, children }: IGalleryContextProviderProps) { - const { isLoading, assets, addAsset, updateAsset, + const { isLoading, assets, addAsset, updateAsset, updateAssets, checkAssetHash: _checkAssetHash, loadAsset: _loadAsset, storeAsset, addArrayValue: _addArrayValue, @@ -254,35 +254,37 @@ export function GalleryContextProvider({ sortFn, children }: IGalleryContextProv } // Renders the assets that we know about already. - setItems(applySort(removeDeletedAssets(assets))); + const items = applySort(removeDeletedAssets(assets)); + setItems(items); + setSelectedItems(items.filter(item => item.selected)); } // // Adds an asset to the start of the gallery. // - async function addGalleryItem(galleryItem: IGalleryItem): Promise { + function addGalleryItem(galleryItem: IGalleryItem): void { addAsset(galleryItem); } // // Updates an asset in the gallery by index. // - async function updateGalleryItem(assetIndex: number, partialGalleryItem: Partial): Promise { + function updateGalleryItem(assetIndex: number, partialGalleryItem: Partial): void { updateAsset(assetIndex, partialGalleryItem); } // // Adds an array value to the asset. // - async function addArrayValue(assetIndex: number, field: string, value: any): Promise { - await _addArrayValue(assetIndex, field, value); + function addArrayValue(assetIndex: number, field: string, value: any): void { + _addArrayValue(assetIndex, field, value); } // // Removes an array value from the asset. // - async function removeArrayValue(assetIndex: number, field: string, value: any): Promise { - await _removeArrayValue(assetIndex, field, value); + function removeArrayValue(assetIndex: number, field: string, value: any): void { + _removeArrayValue(assetIndex, field, value); } // @@ -424,7 +426,7 @@ export function GalleryContextProvider({ sortFn, children }: IGalleryContextProv // // Add the item to the multiple selection. // - async function addToMultipleSelection(item: IGalleryItem): Promise { + function addToMultipleSelection(item: IGalleryItem): void { if (!item.setIndex) { throw new Error(`Asset index is not set`); } @@ -439,7 +441,7 @@ export function GalleryContextProvider({ sortFn, children }: IGalleryContextProv // // Remove the item from the multiple selection. // - async function removeFromMultipleSelection(item: IGalleryItem): Promise { + function removeFromMultipleSelection(item: IGalleryItem): void { if (!item.setIndex) { throw new Error(`Asset index is not set`); } @@ -455,7 +457,7 @@ export function GalleryContextProvider({ sortFn, children }: IGalleryContextProv // // Clears the multiple selection. // - async function clearMultiSelection(): Promise { + function clearMultiSelection(): void { updateAssets(selectedItems.map(item => ({ assetIndex: item.setIndex!, partialAsset: { selected: false }, diff --git a/packages/user-interface/src/context/gallery-item-context.tsx b/packages/user-interface/src/context/gallery-item-context.tsx index a998187..65dcb23 100644 --- a/packages/user-interface/src/context/gallery-item-context.tsx +++ b/packages/user-interface/src/context/gallery-item-context.tsx @@ -23,12 +23,12 @@ export interface IGalleryItemContext { // // Adds an array value to the asset. // - addArrayValue(key: string, value: string): Promise; + addArrayValue(key: string, value: string): void; // // Removes an array value from the asset. // - removeArrayValue(key: string, value: string): Promise; + removeArrayValue(key: string, value: string): void; } const GalleryItemContext = createContext(undefined); @@ -74,7 +74,7 @@ export function GalleryItemContextProvider({ children, asset }: IProps) { // // Adds an array value to the asset. // - async function addArrayValue(field: string, value: any): Promise { + function addArrayValue(field: string, value: any): void { if (asset.setIndex === undefined) { throw new Error(`Asset set index is not set!`); } @@ -89,13 +89,13 @@ export function GalleryItemContextProvider({ children, asset }: IProps) { console.log(`Updated asset:`); //fio: console.log(updatedAsset); //fio: - await _addArrayValue(asset.setIndex, field, value); + _addArrayValue(asset.setIndex, field, value); } // // Removes an array value from the asset. // - async function removeArrayValue(field: string, value: any): Promise { + function removeArrayValue(field: string, value: any): void { if (asset.setIndex === undefined) { throw new Error(`Asset set index is not set!`); } @@ -107,7 +107,7 @@ export function GalleryItemContextProvider({ children, asset }: IProps) { updatedAsset[field] = updatedAsset[field].filter((item: any) => item !== value); setAsset(updatedAsset); - await _removeArrayValue(asset.setIndex, field, value); + _removeArrayValue(asset.setIndex, field, value); } const value: IGalleryItemContext = { diff --git a/packages/user-interface/src/context/gallery-source.tsx b/packages/user-interface/src/context/gallery-source.tsx index 22d24f9..0b11d2b 100644 --- a/packages/user-interface/src/context/gallery-source.tsx +++ b/packages/user-interface/src/context/gallery-source.tsx @@ -32,12 +32,13 @@ export interface IGallerySource { // // Adds an asset to the source. // - addAsset(asset: IGalleryItem): Promise; + addAsset(asset: IGalleryItem): void; // // Updates an existing asset. // - updateAsset(assetIndex: number, partialAsset: Partial): Promise; + updateAsset(assetIndex: number, partialAsset: Partial): void; + // // Update multiple assets with non persisted changes. // @@ -46,12 +47,12 @@ export interface IGallerySource { // // Adds an array value to the asset. // - addArrayValue(assetIndex: number, field: string, value: any): Promise; + addArrayValue(assetIndex: number, field: string, value: any): void; // // Removes an array value from the asset. // - removeArrayValue(assetIndex: number, field: string, value: any): Promise; + removeArrayValue(assetIndex: number, field: string, value: any): void; // // Checks if an asset is already uploaded. diff --git a/packages/user-interface/src/context/upload-context.tsx b/packages/user-interface/src/context/upload-context.tsx index 66a4d96..cb0bd98 100644 --- a/packages/user-interface/src/context/upload-context.tsx +++ b/packages/user-interface/src/context/upload-context.tsx @@ -432,7 +432,7 @@ export function UploadContextProvider({ children }: IProps) { // // Add asset to the gallery. // - await addGalleryItem({ + addGalleryItem({ _id: assetId, width: resolution.width, height: resolution.height, diff --git a/packages/user-interface/src/pages/gallery/components/asset-info.tsx b/packages/user-interface/src/pages/gallery/components/asset-info.tsx index bde0ce9..7519eb3 100644 --- a/packages/user-interface/src/pages/gallery/components/asset-info.tsx +++ b/packages/user-interface/src/pages/gallery/components/asset-info.tsx @@ -36,20 +36,20 @@ export function AssetInfo({ open, onClose, onDeleted }: IAssetInfoProps) { // // Adds a new label to the asset. // - async function onAddLabel() { + function onAddLabel() { const labelName = window.prompt("Enter the new label:"); if (!labelName) { return; } - await addArrayValue("labels", labelName); + addArrayValue("labels", labelName); } // // Removes a label from the asset. // - async function onRemoveLabel(labelName: string) { - await removeArrayValue("labels", labelName); + function onRemoveLabel(labelName: string) { + removeArrayValue("labels", labelName); } //