Skip to content

Commit 3e64afb

Browse files
committed
improve toast logic and add api call for extraction
1 parent bb9bbd7 commit 3e64afb

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

packages/app/src/pages/audit/base.tsx

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Link, Outlet, useParams } from "react-router";
33
import {
44
getAuditManifest,
55
getDependencyManifest,
6+
runExtraction,
67
} from "../../service/api/index.ts";
78
import type {
89
AuditManifest,
@@ -102,15 +103,36 @@ export default function BaseAuditPage() {
102103
[],
103104
);
104105

105-
function extractSymbols() {
106+
async function extractSymbols() {
106107
setBusy(true);
107-
// TODO: Implement
108-
setBusy(false);
108+
const extractionToast = toast({
109+
title: "Extracting symbols",
110+
description: "This may take a while...",
111+
});
112+
try {
113+
await runExtraction(symbolsToExtract);
114+
extractionToast.update({
115+
id: extractionToast.id,
116+
description: "Symbols extracted successfully",
117+
});
118+
} catch (_error) {
119+
extractionToast.update({
120+
id: extractionToast.id,
121+
description: "Failed to extract symbols",
122+
variant: "destructive",
123+
});
124+
} finally {
125+
setBusy(false);
126+
}
109127
}
110128

111129
useEffect(() => {
112130
async function handleOnLoad() {
113131
setBusy(true);
132+
const allPromiseToast = toast({
133+
title: "Loading manifests",
134+
description: "This may take a while...",
135+
});
114136
try {
115137
const dependencyManifestPromise = getDependencyManifest();
116138
const auditManifestPromise = getAuditManifest();
@@ -125,13 +147,14 @@ export default function BaseAuditPage() {
125147
setDependencyManifest(dependencyManifest);
126148
setAuditManifest(auditManifest);
127149

128-
toast({
129-
title: "Successfully loaded project overview",
150+
allPromiseToast.update({
151+
id: allPromiseToast.id,
152+
description: "Manifests loaded successfully",
130153
});
131-
} catch (error) {
132-
toast({
133-
title: "Failed to load project overview",
134-
description: error instanceof Error ? error.message : "Unknown error",
154+
} catch (_error) {
155+
allPromiseToast.update({
156+
id: allPromiseToast.id,
157+
description: "Failed to load manifests",
135158
variant: "destructive",
136159
});
137160
} finally {

packages/app/src/service/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function getAuditManifest() {
3333
}
3434

3535
export async function runExtraction(
36-
symbolsToExtract: SymbolsToExtract[],
36+
symbolsToExtract: SymbolsToExtract,
3737
): Promise<{ success: boolean }> {
3838
const response = await fetch("/api/extractSymbol/", {
3939
method: "POST",

0 commit comments

Comments
 (0)