mirror of
https://github.com/open-webui/computer.git
synced 2026-12-06 11:37:58 -05:00
refac
This commit is contained in:
1 parent
eb2570b405
commit
9d9f5786cb
8 files changed
+143
-18
No files matched your search
@@ -17,8 +17,13 @@ export const savePreferences = (data: Record<string, unknown>) =>
|
||||
|
||||
// ── Workspace list (sidebar) ────────────────────────────────────
|
||||
|
||||
export const getWorkspaceList = () =>
|
||||
fetchJSON<{ path: string; name: string }[]>('/api/state/workspaces');
|
||||
export interface WorkspaceListItem {
|
||||
path: string;
|
||||
name: string;
|
||||
unread_count: number;
|
||||
}
|
||||
|
||||
export const getWorkspaceList = () => fetchJSON<WorkspaceListItem[]>('/api/state/workspaces');
|
||||
|
||||
// ── Single workspace CRUD ───────────────────────────────────────
|
||||
|
||||
|
||||
@@ -173,15 +173,27 @@
|
||||
active?: boolean;
|
||||
updated_at?: number;
|
||||
last_read_at?: number;
|
||||
workspace_unread_count?: number;
|
||||
}) {
|
||||
if (
|
||||
!data.title &&
|
||||
typeof data.active !== 'boolean' &&
|
||||
typeof data.updated_at !== 'number' &&
|
||||
typeof data.last_read_at !== 'number'
|
||||
typeof data.last_read_at !== 'number' &&
|
||||
typeof data.workspace_unread_count !== 'number'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const unreadCount = data.workspace_unread_count;
|
||||
if (data.workspace && typeof unreadCount === 'number') {
|
||||
workspaceList.update((workspaces) =>
|
||||
workspaces.map((workspace) =>
|
||||
workspace.path === data.workspace
|
||||
? { ...workspace, unread_count: unreadCount }
|
||||
: workspace
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
let known = false;
|
||||
wsChatsCache = new Map(
|
||||
@@ -310,9 +322,17 @@
|
||||
{:else}
|
||||
<Icon name="folder" size={14} />
|
||||
{/if}
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{ws.name}</span
|
||||
>
|
||||
<span class="min-w-0 truncate text-left">{ws.name}</span>
|
||||
{#if ws.unread_count > 0}
|
||||
<span
|
||||
class="inline-flex h-4 min-w-4 shrink-0 items-center justify-center rounded-md bg-sky-500/10 px-1 text-[0.625rem] font-semibold text-sky-600 dark:bg-sky-400/10 dark:text-sky-300"
|
||||
>
|
||||
{new Intl.NumberFormat(undefined, {
|
||||
notation: 'compact',
|
||||
compactDisplay: 'short'
|
||||
}).format(ws.unread_count)}
|
||||
</span>
|
||||
{/if}
|
||||
</a>
|
||||
<span
|
||||
class="flex items-center justify-center w-4 h-4 shrink-0 text-gray-400 opacity-0 group-hover:opacity-100 hover:text-gray-600 dark:hover:text-gray-300 transition-all duration-75"
|
||||
|
||||
@@ -281,7 +281,7 @@ export const homeState = writable<HomeState>({
|
||||
});
|
||||
|
||||
/** List of all workspace summaries for the sidebar. */
|
||||
export const workspaceList = writable<{ path: string; name: string }[]>([]);
|
||||
export const workspaceList = writable<{ path: string; name: string; unread_count: number }[]>([]);
|
||||
|
||||
/** Global user preferences. */
|
||||
export const sidebarOpen = writable(
|
||||
@@ -825,7 +825,7 @@ export function addWorkspace(path: string): void {
|
||||
// Update workspace list for sidebar
|
||||
workspaceList.update((list) => {
|
||||
if (list.some((w) => w.path === path)) return list;
|
||||
return [...list, { path, name }];
|
||||
return [...list, { path, name, unread_count: 0 }];
|
||||
});
|
||||
|
||||
// Append to order
|
||||
|
||||
Reference in new issue
Block a user