Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
Add toast messages for asset manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkmanZA committed Oct 20, 2023
1 parent 925f9a0 commit b2b9100
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/electron/lib/api/apis/ProjectApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export class ProjectApi implements ElectronMainApi<ProjectApi> {
if (res === -1 && graphs) this.blix.graphManager.deleteGraphs(graphs);
}

async addCacheObjects(projectUUID: UUID, cacheUUIDs: UUID[]) {
this.blix.projectManager.addCacheObjects(projectUUID, cacheUUIDs);
async addCacheObjects(projectUUID: UUID, cacheUUIDs: UUID[]): Promise<IpcResponse<string>> {
return this.blix.projectManager.addCacheObjects(projectUUID, cacheUUIDs);
}

async removeCacheObjects(projectUUID: UUID, cacheUUIDs: UUID[]) {
this.blix.projectManager.removeCacheObjects(projectUUID, cacheUUIDs);
async removeCacheObjects(projectUUID: UUID, cacheUUIDs: UUID[]): Promise<IpcResponse<string>> {
return this.blix.projectManager.removeCacheObjects(projectUUID, cacheUUIDs);
}
}
19 changes: 15 additions & 4 deletions src/electron/lib/projects/CoreProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { UUID } from "../../../shared/utils/UniqueEntity";
import type { PathLike } from "fs";
import type { GraphToJSON } from "../../lib/core-graph/CoreGraphExporter";
import { layoutTemplate } from "../../../frontend/lib/Project";
import { IpcResponse } from "../../lib/api/MainApi";
// Encapsulates the backend state for one of the open Blix projects
export class CoreProject extends UniqueEntity {
private _name: string;
Expand Down Expand Up @@ -110,12 +111,22 @@ export class CoreProject extends UniqueEntity {
this._saved = flag;
}

public addCacheObjects(cacheUUIDs: UUID[]) {
this._cache = [...this._cache, ...cacheUUIDs];
public addCacheObjects(cacheUUIDs: UUID[]): IpcResponse<string> {
try {
this._cache = [...this._cache, ...cacheUUIDs];
return { success: true, data: "Asset successfully added" };
} catch (e: any) {
return { success: false, data: e };
}
}

public removeCacheObjects(cacheUUIDs: UUID[]) {
this._cache = this._cache.filter((id) => !cacheUUIDs.includes(id));
public removeCacheObjects(cacheUUIDs: UUID[]): IpcResponse<string> {
try {
this._cache = this._cache.filter((id) => !cacheUUIDs.includes(id));
return { success: true, data: "Asset successfully removed" };
} catch (e: any) {
return { success: false, data: e };
}
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/electron/lib/projects/ProjectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { dialog } from "electron";
import type { LayoutPanel } from "../../../shared/types/index";
import { saveProjectCommand } from "./ProjectCommands";
import { Blix } from "../Blix";
import { IpcResponse } from "../../lib/api/MainApi";

export class ProjectManager {
private _projects: { [id: string]: CoreProject };
Expand Down Expand Up @@ -204,14 +205,16 @@ export class ProjectManager {
this.onProjectChanged(projectId);
}

public addCacheObjects(projectUUID: UUID, cacheUUIDs: UUID[]) {
this._projects[projectUUID].addCacheObjects(cacheUUIDs);
public addCacheObjects(projectUUID: UUID, cacheUUIDs: UUID[]): IpcResponse<string> {
const res = this._projects[projectUUID].addCacheObjects(cacheUUIDs);
this.onProjectChanged(projectUUID);
return res;
}

public removeCacheObjects(projectUUID: UUID, cacheUUIDs: UUID[]) {
this._projects[projectUUID].removeCacheObjects(cacheUUIDs);
public removeCacheObjects(projectUUID: UUID, cacheUUIDs: UUID[]): IpcResponse<string> {
const res = this._projects[projectUUID].removeCacheObjects(cacheUUIDs);
this.onProjectChanged(projectUUID);
return res;
}
}

Expand Down
18 changes: 11 additions & 7 deletions src/frontend/ui/tiles/Assets.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import Fa from "svelte-fa";
import { toastStore } from "../../lib/stores/ToastStore";
import { projectsStore } from "../../lib/stores/ProjectStore";
import { readable } from "svelte/store";
let selectedCacheItems: CacheUUID[] = [];
// Not used at the moment
Expand Down Expand Up @@ -73,8 +72,12 @@
name: file.name,
contentType: file.type,
});
if ($projectsStore.activeProject && cacheId)
await window.apis.projectApi.addCacheObjects($projectsStore.activeProject.id, [cacheId]);
if ($projectsStore.activeProject && cacheId) {
const res = await window.apis.projectApi.addCacheObjects($projectsStore.activeProject.id, [
cacheId,
]);
toastStore.trigger({ message: res.data, type: res.success ? "success" : "error" });
}
} catch (error) {
console.error(error);
}
Expand All @@ -96,11 +99,13 @@
toastStore.trigger({ message: "No asset selected.", type: "warn" });
return;
}
if ($projectsStore.activeProject)
await window.apis.projectApi.removeCacheObjects(
if ($projectsStore.activeProject) {
const res = await window.apis.projectApi.removeCacheObjects(
$projectsStore.activeProject.id,
selectedCacheItems
);
toastStore.trigger({ message: res.data, type: res.success ? "success" : "error" });
}
await cacheStore.deleteSelectedAssets(selectedCacheItems);
}
Expand All @@ -117,8 +122,7 @@
return url;
}
let cacheIds = readable<string[]>([]);
$: cacheIds = projectsStore.getReactiveActiveProjectCacheIds();
let cacheIds = projectsStore.getReactiveActiveProjectCacheIds();
</script>

{#if $projectsStore.activeProject}
Expand Down

0 comments on commit b2b9100

Please sign in to comment.