Skip to content

Commit

Permalink
Removed unecessary async functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleydavis committed Jul 7, 2024
1 parent 575a2e8 commit 24fdb96
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 41 deletions.
6 changes: 3 additions & 3 deletions packages/user-interface/src/components/gallery-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}}
>
Expand Down
9 changes: 5 additions & 4 deletions packages/user-interface/src/context/asset-database-source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function AssetDatabaseProvider({ children }: IAssetDatabaseProviderProps)
//
// Adds an asset to the source.
//
async function addAsset(asset: IGalleryItem): Promise<void> {
function addAsset(asset: IGalleryItem): void {

setAssets([ { ...asset, setIndex: 0 } ]
.concat(
Expand Down Expand Up @@ -108,7 +108,7 @@ export function AssetDatabaseProvider({ children }: IAssetDatabaseProviderProps)
//
// Updates an existing asset.
//
async function updateAsset(assetIndex: number, partialAsset: Partial<IGalleryItem>): Promise<void> {
function updateAsset(assetIndex: number, partialAsset: Partial<IGalleryItem>): void {

const assetId = assets[assetIndex]._id;
const updatedAsset = { ...assets[assetIndex], ...partialAsset };
Expand Down Expand Up @@ -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<void> {
function addArrayValue(assetIndex: number, field: string, value: any): void {
const assetId = assets[assetIndex]._id;
const updatedAsset: any = { ...assets[assetIndex] };
if (updatedAsset[field] === undefined) {
Expand Down Expand Up @@ -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<void> {
function removeArrayValue(assetIndex: number, field: string, value: any): void {
const assetId = assets[assetIndex]._id;
const updatedAsset: any = { ...assets[assetIndex] };
if (updatedAsset[field] === undefined) {
Expand Down
40 changes: 21 additions & 19 deletions packages/user-interface/src/context/gallery-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ export interface IGalleryContext {
//
// Adds an item to the the gallery.
//
addGalleryItem(galleryItem: IGalleryItem): Promise<void>;
addGalleryItem(galleryItem: IGalleryItem): void;

//
// Updates an item in the gallery by index.
//
updateGalleryItem(assetIndex: number, partialGalleryItem: Partial<IGalleryItem>): Promise<void>;
updateGalleryItem(assetIndex: number, partialGalleryItem: Partial<IGalleryItem>): void;

//
// Adds an array value to the asset.
//
addArrayValue(assetIndex: number, field: string, value: any): Promise<void>;
addArrayValue(assetIndex: number, field: string, value: any): void;

//
// Removes an array value from the asset.
//
removeArrayValue(assetIndex: number, field: string, value: any): Promise<void>;
removeArrayValue(assetIndex: number, field: string, value: any): void;

//
// Checks if an asset is already uploaded.
Expand Down Expand Up @@ -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<void>;
addToMultipleSelection(item: IGalleryItem): void;

//
// Remove the item from the multiple selection.
//
removeFromMultipleSelection(item: IGalleryItem): Promise<void>;
removeFromMultipleSelection(item: IGalleryItem): void;

//
// Clears the multiple selection.
//
clearMultiSelection(): Promise<void>;
clearMultiSelection(): void;

//
// The current search text.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<void> {
function addGalleryItem(galleryItem: IGalleryItem): void {
addAsset(galleryItem);
}

//
// Updates an asset in the gallery by index.
//
async function updateGalleryItem(assetIndex: number, partialGalleryItem: Partial<IGalleryItem>): Promise<void> {
function updateGalleryItem(assetIndex: number, partialGalleryItem: Partial<IGalleryItem>): void {
updateAsset(assetIndex, partialGalleryItem);
}

//
// Adds an array value to the asset.
//
async function addArrayValue(assetIndex: number, field: string, value: any): Promise<void> {
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<void> {
await _removeArrayValue(assetIndex, field, value);
function removeArrayValue(assetIndex: number, field: string, value: any): void {
_removeArrayValue(assetIndex, field, value);
}

//
Expand Down Expand Up @@ -424,7 +426,7 @@ export function GalleryContextProvider({ sortFn, children }: IGalleryContextProv
//
// Add the item to the multiple selection.
//
async function addToMultipleSelection(item: IGalleryItem): Promise<void> {
function addToMultipleSelection(item: IGalleryItem): void {
if (!item.setIndex) {
throw new Error(`Asset index is not set`);
}
Expand All @@ -439,7 +441,7 @@ export function GalleryContextProvider({ sortFn, children }: IGalleryContextProv
//
// Remove the item from the multiple selection.
//
async function removeFromMultipleSelection(item: IGalleryItem): Promise<void> {
function removeFromMultipleSelection(item: IGalleryItem): void {
if (!item.setIndex) {
throw new Error(`Asset index is not set`);
}
Expand All @@ -455,7 +457,7 @@ export function GalleryContextProvider({ sortFn, children }: IGalleryContextProv
//
// Clears the multiple selection.
//
async function clearMultiSelection(): Promise<void> {
function clearMultiSelection(): void {
updateAssets(selectedItems.map(item => ({
assetIndex: item.setIndex!,
partialAsset: { selected: false },
Expand Down
12 changes: 6 additions & 6 deletions packages/user-interface/src/context/gallery-item-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export interface IGalleryItemContext {
//
// Adds an array value to the asset.
//
addArrayValue(key: string, value: string): Promise<void>;
addArrayValue(key: string, value: string): void;

//
// Removes an array value from the asset.
//
removeArrayValue(key: string, value: string): Promise<void>;
removeArrayValue(key: string, value: string): void;
}

const GalleryItemContext = createContext<IGalleryItemContext | undefined>(undefined);
Expand Down Expand Up @@ -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<void> {
function addArrayValue(field: string, value: any): void {
if (asset.setIndex === undefined) {
throw new Error(`Asset set index is not set!`);
}
Expand All @@ -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<void> {
function removeArrayValue(field: string, value: any): void {
if (asset.setIndex === undefined) {
throw new Error(`Asset set index is not set!`);
}
Expand All @@ -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 = {
Expand Down
9 changes: 5 additions & 4 deletions packages/user-interface/src/context/gallery-source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ export interface IGallerySource {
//
// Adds an asset to the source.
//
addAsset(asset: IGalleryItem): Promise<void>;
addAsset(asset: IGalleryItem): void;

//
// Updates an existing asset.
//
updateAsset(assetIndex: number, partialAsset: Partial<IGalleryItem>): Promise<void>;
updateAsset(assetIndex: number, partialAsset: Partial<IGalleryItem>): void;

//
// Update multiple assets with non persisted changes.
//
Expand All @@ -46,12 +47,12 @@ export interface IGallerySource {
//
// Adds an array value to the asset.
//
addArrayValue(assetIndex: number, field: string, value: any): Promise<void>;
addArrayValue(assetIndex: number, field: string, value: any): void;

//
// Removes an array value from the asset.
//
removeArrayValue(assetIndex: number, field: string, value: any): Promise<void>;
removeArrayValue(assetIndex: number, field: string, value: any): void;

//
// Checks if an asset is already uploaded.
Expand Down
2 changes: 1 addition & 1 deletion packages/user-interface/src/context/upload-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//
Expand Down

0 comments on commit 24fdb96

Please sign in to comment.