Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Workspace creation improvement in desktop
Hakan Shehu0383c9404e2c
diff --git a/desktop/src/components/app.tsx b/desktop/src/components/app.tsxindex 7f42ae47..a38c3899 100644--- a/desktop/src/components/app.tsx+++ b/desktop/src/components/app.tsx@@ -24,7 +24,7 @@ export function App() {});}- }, [])+ }, [account, workspaces])if (!account) {return <Login />;diff --git a/desktop/src/components/workspaces/workspace-create.tsx b/desktop/src/components/workspaces/workspace-create.tsxindex 4efb1a49..8316d0e9 100644--- a/desktop/src/components/workspaces/workspace-create.tsx+++ b/desktop/src/components/workspaces/workspace-create.tsx@@ -44,13 +44,7 @@ export function WorkspaceCreate() {try {const { data } = await axios.post<Workspace>('v1/workspaces', values);if (data) {- await window.globalDb.addWorkspace({- id: data.id,- name: data.name,- role: 'owner',- avatar: null,- description: data.description,- });+ await window.globalDb.addWorkspace(data);dispatch(addWorkspace(data));navigate(`/${data.id}`);} else {diff --git a/desktop/src/data/global-db.ts b/desktop/src/data/global-db.tsindex bb9388b9..c6168a5f 100644--- a/desktop/src/data/global-db.ts+++ b/desktop/src/data/global-db.ts@@ -5,28 +5,60 @@ import {Workspace} from "@/types/workspaces";const path = app.getPath('userData');const globalDb = new database(`${path}/global.db`);-export function initGlobalDb() {- const createWorkspacesTable = `+const createWorkspacesTableQuery = `CREATE TABLE IF NOT EXISTS workspaces (id TEXT PRIMARY KEY,name TEXT NOT NULL,+ description TEXT,avatar TEXT,- role TEXT NOT NULL,- created_at DATE NOT NULL+ version_id TEXT NOT NULL,+ account_id TEXT NOT NULL,+ role INTEGER NOT NULL,+ user_node_id TEXT NOT NULL);`;- globalDb.exec(createWorkspacesTable);+const selectWorkspacesQuery = `+ SELECT+ id,+ name,+ description,+ avatar,+ version_id as versionId,+ account_id as accountId,+ role,+ user_node_id as userNodeId+ FROM workspaces+`;++const insertWorkspaceQuery = `+ INSERT INTO workspaces+ (+ id,+ name,+ description,+ avatar,+ version_id,+ account_id,+ role,+ user_node_id+ )+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)+`;++function getWorkspaces(): Workspace[] {+ const stmt = globalDb.prepare<[], Workspace>(selectWorkspacesQuery);+ return stmt.all();}-export function getWorkspaces(): Workspace[] {- const stmt = globalDb.prepare<[], Workspace>('SELECT id, name, avatar, role FROM workspaces');- return stmt.all();+function addWorkspace(workspace: Workspace) {+ const stmt = globalDb.prepare(insertWorkspaceQuery);+ console.log('workspace', workspace);+ stmt.run(workspace.id, workspace.name, workspace.description, workspace.avatar, workspace.versionId, workspace.accountId, workspace.role, workspace.userNodeId);}-export function addWorkspace(workspace: Workspace) {- const stmt = globalDb.prepare('INSERT INTO workspaces (id, name, avatar, role, created_at) VALUES (?, ?, ?, ?, ?)');- stmt.run(workspace.id, workspace.name, workspace.avatar, workspace.role, new Date().toISOString());+export function initGlobalDb() {+ globalDb.exec(createWorkspacesTableQuery);}export function defineGlobalDbHandlers() {diff --git a/desktop/src/types/workspaces.ts b/desktop/src/types/workspaces.tsindex 340f5e77..5f0e7ced 100644--- a/desktop/src/types/workspaces.ts+++ b/desktop/src/types/workspaces.ts@@ -1,7 +1,17 @@+export enum WorkspaceRole {+ Owner = 1,+ Admin = 2,+ Collaborator = 3,+ Viewer = 4+}+export type Workspace = {id: string;name: string;- description: string;+ description?: string | null;avatar?: string | null;- role: string;+ versionId: string;+ accountId: string;+ role: WorkspaceRole;+ userNodeId: string;};\ No newline at end of file