fix: search store now parses API envelope response correctly

The search API returns { success, data: [...] } but the store was
looking for data.apps and data.boards (which don't exist). Fixed to
read from data.data[] and also added url/icon fields to search API
response so app results are clickable and show icons.
This commit is contained in:
2026-03-25 21:12:17 +03:00
parent 92eeeadec0
commit bcde710cab
2 changed files with 32 additions and 32 deletions
+15 -18
View File
@@ -100,31 +100,28 @@ class SearchStore {
return;
}
const data = await res.json();
const json = await res.json();
const results = json.data ?? [];
const items: SearchResultItem[] = [];
if (data.apps) {
for (const app of data.apps) {
for (const item of results) {
if (item.type === 'app') {
items.push({
type: 'app',
id: app.id,
name: app.name,
description: app.description ?? null,
url: app.url,
icon: app.icon ?? null
id: item.id,
name: item.name,
description: item.description ?? null,
url: item.url ?? `/apps/${item.id}`,
icon: item.icon ?? null
});
}
}
if (data.boards) {
for (const board of data.boards) {
} else if (item.type === 'board') {
items.push({
type: 'board',
id: board.id,
name: board.name,
description: board.description ?? null,
url: `/boards/${board.id}`,
icon: board.icon ?? null
id: item.id,
name: item.name,
description: item.description ?? null,
url: `/boards/${item.id}`,
icon: item.icon ?? null
});
}
}
+13 -10
View File
@@ -11,6 +11,8 @@ interface SearchResult {
readonly id: string;
readonly name: string;
readonly description: string | null;
readonly url?: string;
readonly icon?: string | null;
readonly category?: string | null;
}
@@ -39,6 +41,9 @@ export const GET: RequestHandler = async (event) => {
select: {
id: true,
name: true,
url: true,
icon: true,
iconType: true,
description: true,
category: true
},
@@ -66,14 +71,18 @@ export const GET: RequestHandler = async (event) => {
// Filter apps by permission
const filteredApps: SearchResult[] = [];
for (const app of apps) {
if (isAdmin) {
filteredApps.push({
const appResult: SearchResult = {
type: 'app',
id: app.id,
name: app.name,
description: app.description,
url: app.url,
icon: app.icon,
category: app.category
});
};
if (isAdmin) {
filteredApps.push(appResult);
continue;
}
@@ -84,13 +93,7 @@ export const GET: RequestHandler = async (event) => {
PermissionLevel.VIEW
);
if (check.hasPermission) {
filteredApps.push({
type: 'app',
id: app.id,
name: app.name,
description: app.description,
category: app.category
});
filteredApps.push(appResult);
}
}