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
Open in modal and other file improvements (#263)
Hakan Shehu22b8ce69705c
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex a09c23c0..14aed450 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -304,7 +304,7 @@ ipcMain.handle(const extension = app.path.extension(file.name);const mimeType = file.type;const subtype = extractFileSubtype(mimeType);- const filePath = app.path.tempFile(file.name);+ const filePath = app.path.tempFile(id + extension);await app.fs.writeFile(filePath, file.buffer);await app.database@@ -323,6 +323,15 @@ ipcMain.handle(.execute();const url = await app.fs.url(filePath);+ if (!url) {+ await app.fs.delete(filePath);+ await app.database+ .deleteFrom('temp_files')+ .where('id', '=', id)+ .execute();++ throw new Error('Failed to save temp file');+ }return {id,diff --git a/apps/desktop/src/main/file-system.ts b/apps/desktop/src/main/file-system.tsindex 8a725d01..9069f881 100644--- a/apps/desktop/src/main/file-system.ts+++ b/apps/desktop/src/main/file-system.ts@@ -44,7 +44,12 @@ export class DesktopFileSystem implements FileSystem {await fs.promises.rm(path, { recursive: true, force: true });}- public async url(path: string): Promise<string> {+ public async url(path: string): Promise<string | null> {+ const exists = await this.exists(path);+ if (!exists) {+ return null;+ }+const base64Path = Buffer.from(path).toString('base64');return `local://files/${base64Path}`;}diff --git a/apps/web/src/services/file-system.ts b/apps/web/src/services/file-system.tsindex 25ae502c..0b62f20a 100644--- a/apps/web/src/services/file-system.ts+++ b/apps/web/src/services/file-system.ts@@ -216,10 +216,18 @@ export class WebFileSystem implements FileSystem {await writable.close();}- public async url(path: string): Promise<string> {- const { parent, name } = await this.getFileLocation(path, false);- const fileHandle = await parent.getFileHandle(name);- const file = await fileHandle.getFile();- return URL.createObjectURL(file);+ public async url(path: string): Promise<string | null> {+ try {+ const { parent, name } = await this.getFileLocation(path, false);+ const fileHandle = await parent.getFileHandle(name);+ if (!fileHandle) {+ return null;+ }++ const file = await fileHandle.getFile();+ return URL.createObjectURL(file);+ } catch {+ return null;+ }}}diff --git a/apps/web/src/workers/dedicated.ts b/apps/web/src/workers/dedicated.tsindex 59998c6d..7bd3f745 100644--- a/apps/web/src/workers/dedicated.ts+++ b/apps/web/src/workers/dedicated.ts@@ -405,7 +405,7 @@ const api: ColanodeWorkerApi = {const extension = path.extension(file.name);const mimeType = file.type;const subtype = extractFileSubtype(mimeType);- const filePath = path.tempFile(file.name);+ const filePath = path.tempFile(id + extension);const arrayBuffer = await file.arrayBuffer();const fileData = new Uint8Array(arrayBuffer);@@ -449,6 +449,11 @@ const api: ColanodeWorkerApi = {}const url = await fs.url(filePath);+ if (!url) {+ await fs.delete(filePath);+ return Promise.reject(new Error('Failed to save temp file'));+ }+return {id,name: file.name,diff --git a/packages/client/src/handlers/mutations/files/temp-file-create.ts b/packages/client/src/handlers/mutations/files/temp-file-create.tsindex f4eccd19..3bee7fbc 100644--- a/packages/client/src/handlers/mutations/files/temp-file-create.ts+++ b/packages/client/src/handlers/mutations/files/temp-file-create.ts@@ -1,3 +1,4 @@+import { eventBus, mapTempFile } from '@colanode/client/lib';import { MutationHandler } from '@colanode/client/lib/types';import {TempFileCreateMutationInput,@@ -17,8 +18,9 @@ export class TempFileCreateMutationHandlerasync handleMutation(input: TempFileCreateMutationInput): Promise<TempFileCreateMutationOutput> {- await this.app.database+ const createdTempFile = await this.app.database.insertInto('temp_files')+ .returningAll().values({id: input.id,name: input.name,@@ -31,7 +33,25 @@ export class TempFileCreateMutationHandleropened_at: new Date().toISOString(),}).onConflict((oc) => oc.doNothing())- .execute();+ .executeTakeFirst();++ if (!createdTempFile) {+ return {+ success: false,+ };+ }++ const url = await this.app.fs.url(createdTempFile.path);+ if (!url) {+ return {+ success: false,+ };+ }++ eventBus.publish({+ type: 'temp.file.created',+ tempFile: mapTempFile(createdTempFile, url),+ });return {success: true,diff --git a/packages/client/src/handlers/queries/files/temp-file-list.ts b/packages/client/src/handlers/queries/files/temp-file-list.tsindex cf9b09f9..bc5e5be3 100644--- a/packages/client/src/handlers/queries/files/temp-file-list.ts+++ b/packages/client/src/handlers/queries/files/temp-file-list.ts@@ -57,6 +57,16 @@ export class TempFileListQueryHandlerconst result: TempFile[] = [];for (const tempFile of tempFiles) {const url = await this.app.fs.url(tempFile.path);+ if (!url) {+ await this.app.fs.delete(tempFile.path);+ await this.app.database+ .deleteFrom('temp_files')+ .where('id', '=', tempFile.id)+ .execute();++ continue;+ }+result.push(mapTempFile(tempFile, url));}diff --git a/packages/client/src/jobs/token-delete.ts b/packages/client/src/jobs/token-delete.tsindex 27ac4b0e..2984a072 100644--- a/packages/client/src/jobs/token-delete.ts+++ b/packages/client/src/jobs/token-delete.ts@@ -44,13 +44,6 @@ export class TokenDeleteJobHandler implements JobHandler<TokenDeleteInput> {};}- if (!server.isAvailable) {- return {- type: 'retry',- delay: ms('1 minute'),- };- }-try {await this.app.client.delete(`${server.httpBaseUrl}/v1/auth/logout`, {headers: {diff --git a/packages/client/src/services/asset-service.ts b/packages/client/src/services/asset-service.tsindex b363cad8..456b4ebb 100644--- a/packages/client/src/services/asset-service.ts+++ b/packages/client/src/services/asset-service.ts@@ -45,6 +45,16 @@ export class AssetService {if (updatedAvatar) {const url = await this.app.fs.url(updatedAvatar.path);+ if (!url) {+ await this.app.fs.delete(updatedAvatar.path);+ await this.app.database+ .deleteFrom('avatars')+ .where('id', '=', avatar)+ .execute();++ return null;+ }+return mapAvatar(updatedAvatar, url);}@@ -115,6 +125,16 @@ export class AssetService {}const url = await this.app.fs.url(avatarPath);+ if (!url) {+ await this.app.fs.delete(avatarPath);+ await this.app.database+ .deleteFrom('avatars')+ .where('id', '=', avatar)+ .execute();++ return false;+ }+eventBus.publish({type: 'avatar.created',avatar: mapAvatar(createdAvatar, url),diff --git a/packages/client/src/services/file-system.ts b/packages/client/src/services/file-system.tsindex fb6c2ca9..9cd129a6 100644--- a/packages/client/src/services/file-system.ts+++ b/packages/client/src/services/file-system.ts@@ -10,5 +10,5 @@ export interface FileSystem {listFiles(path: string): Promise<string[]>;readFile(path: string): Promise<Uint8Array>;writeFile(path: string, data: Uint8Array): Promise<void>;- url(path: string): Promise<string>;+ url(path: string): Promise<string | null>;}diff --git a/packages/client/src/services/workspaces/file-service.ts b/packages/client/src/services/workspaces/file-service.tsindex d501607d..2d7ddc81 100644--- a/packages/client/src/services/workspaces/file-service.ts+++ b/packages/client/src/services/workspaces/file-service.ts@@ -44,11 +44,11 @@ export class FileService {this.filesDir = this.workspace.account.app.path.workspaceFiles(this.workspace.userId);-- this.app.fs.makeDirectory(this.filesDir);}public async init(): Promise<void> {+ await this.app.fs.makeDirectory(this.filesDir);+// if the download was interrupted, we need to reset the status on app startawait this.workspace.database.updateTable('downloads')diff --git a/packages/ui/src/components/files/file-block.tsx b/packages/ui/src/components/files/file-block.tsxindex d1c935a2..503521bd 100644--- a/packages/ui/src/components/files/file-block.tsx+++ b/packages/ui/src/components/files/file-block.tsx@@ -26,33 +26,27 @@ export const FileBlock = ({ id }: FileBlockProps) => {const file = nodeGetQuery.data as LocalFileNode;const canPreview = canPreviewFile(file.attributes.subtype);- if (canPreview) {- return (- <Link- from="/workspace/$userId"- to="$nodeId"- params={{ nodeId: id }}- className="flex h-72 max-h-72 max-w-128 w-full cursor-pointer overflow-hidden rounded-md p-2 hover:bg-muted/50"- >- <FilePreview file={file} />- </Link>- );- }-return (<Link- from="/workspace/$userId"- to="$nodeId"- params={{ nodeId: id }}- className="flex flex-row gap-4 items-center w-full cursor-pointer overflow-hidden rounded-md p-2 pl-0 hover:bg-accent"+ from="/workspace/$userId/$nodeId"+ to="modal/$modalNodeId"+ params={{ modalNodeId: id }}>- <FileIcon mimeType={file.attributes.mimeType} className="size-10" />- <div className="flex flex-col gap-1">- <div className="text-sm font-medium">{file.attributes.name}</div>- <div className="text-xs text-muted-foreground">- {file.attributes.mimeType}+ {canPreview ? (+ <div className="flex h-72 max-h-72 max-w-lg w-full cursor-pointer overflow-hidden rounded-md p-2 hover:bg-muted/50 items-center justify-center">+ <FilePreview file={file} />+ </div>+ ) : (+ <div className="flex flex-row gap-4 items-center w-full cursor-pointer overflow-hidden rounded-md p-2 pl-0 hover:bg-accent">+ <FileIcon mimeType={file.attributes.mimeType} className="size-10" />+ <div className="flex flex-col gap-1">+ <div className="text-sm font-medium">{file.attributes.name}</div>+ <div className="text-xs text-muted-foreground">+ {file.attributes.mimeType}+ </div>+ </div></div>- </div>+ )}</Link>);};diff --git a/packages/ui/src/components/files/file-preview.tsx b/packages/ui/src/components/files/file-preview.tsxindex b27fa8e6..50b2d881 100644--- a/packages/ui/src/components/files/file-preview.tsx+++ b/packages/ui/src/components/files/file-preview.tsx@@ -24,16 +24,16 @@ export const FilePreview = ({ file }: FilePreviewProps) => {autoDownload: isReady,});- if (!isReady) {- return <FileNotUploaded mimeType={file.attributes.mimeType} />;- }-if (localFileQuery.isPending) {return null;}const localFile = localFileQuery.data;if (!localFile) {+ if (!isReady) {+ return <FileNotUploaded mimeType={file.attributes.mimeType} />;+ }+return <FileNoPreview mimeType={file.attributes.mimeType} />;}diff --git a/packages/ui/src/components/folders/folder-files.tsx b/packages/ui/src/components/folders/folder-files.tsxindex 23919fa3..d69a66dd 100644--- a/packages/ui/src/components/folders/folder-files.tsx+++ b/packages/ui/src/components/folders/folder-files.tsx@@ -25,7 +25,7 @@ export const FolderFiles = ({layout: folderLayout,}: FolderFilesProps) => {const workspace = useWorkspace();- const navigate = useNavigate({ from: '/workspace/$userId' });+ const navigate = useNavigate({ from: '/workspace/$userId/$nodeId' });const [lastPage] = useState<number>(1);const inputs: FileListQueryInput[] = Array.from({@@ -52,8 +52,8 @@ export const FolderFiles = ({},onDoubleClick: (_, id) => {navigate({- to: '$nodeId',- params: { nodeId: id },+ to: 'modal/$modalNodeId',+ params: { modalNodeId: id },});},onMove: () => {},diff --git a/packages/ui/src/components/nodes/node-modal.tsx b/packages/ui/src/components/nodes/node-modal.tsxindex 9c9f0654..375b7225 100644--- a/packages/ui/src/components/nodes/node-modal.tsx+++ b/packages/ui/src/components/nodes/node-modal.tsx@@ -26,6 +26,7 @@ export const NodeModal = ({ nodeId }: NodeModalProps) => {});}}}+ modal={true}><DialogContentclassName="w-[90vw] h-[90vh] max-w-[90vw] max-h-[90vh] min-w-[90vw] min-h-[90vh] p-2"diff --git a/packages/ui/src/components/servers/server-card.tsx b/packages/ui/src/components/servers/server-card.tsxindex 8ee4509f..8f08d729 100644--- a/packages/ui/src/components/servers/server-card.tsx+++ b/packages/ui/src/components/servers/server-card.tsx@@ -38,9 +38,8 @@ export const ServerCard = ({ server, onSelect }: ServerCardProps) => {return (<>- <button+ <divonClick={handleServerClick}- disabled={isSyncing}className="group/server relative flex w-full flex-row items-center gap-3 rounded-lg border border-border/60 bg-background p-2 text-left transition-all hover:cursor-pointer hover:border-border hover:bg-accent hover:shadow-md disabled:opacity-50 disabled:cursor-not-allowed"><ServerAvatar@@ -67,7 +66,7 @@ export const ServerCard = ({ server, onSelect }: ServerCardProps) => {<SettingsIcon className="size-4" />)}</button>- </button>+ </div><ServerSettingsDialogserver={server}open={openSettings}diff --git a/packages/ui/src/editor/extensions/commander.tsx b/packages/ui/src/editor/extensions/commander.tsxindex e6556edc..de86cde6 100644--- a/packages/ui/src/editor/extensions/commander.tsx+++ b/packages/ui/src/editor/extensions/commander.tsx@@ -145,10 +145,10 @@ const CommandList = ({return items.length > 0 ? (<FloatingPortal>- <div ref={refs.setFloating} style={floatingStyles}>+ <div ref={refs.setFloating} style={{ ...floatingStyles, zIndex: 60 }}><divid="slash-command"- className="z-50 min-w-[8rem] w-80 rounded-md border bg-popover text-popover-foreground p-1 shadow-md animate-in fade-in-0 zoom-in-95 slide-in-from-top-2 overflow-hidden"+ className="z-50 min-w-32 w-80 rounded-md border bg-popover text-popover-foreground p-1 shadow-md animate-in fade-in-0 zoom-in-95 slide-in-from-top-2 overflow-hidden"><ScrollArea className="h-80"><ScrollViewport ref={scrollContainer}>diff --git a/packages/ui/src/editor/extensions/mention.tsx b/packages/ui/src/editor/extensions/mention.tsxindex b8f16f16..8b46aacc 100644--- a/packages/ui/src/editor/extensions/mention.tsx+++ b/packages/ui/src/editor/extensions/mention.tsx@@ -135,10 +135,10 @@ const CommandList = ({return items.length > 0 ? (<FloatingPortal>- <div ref={refs.setFloating} style={floatingStyles}>+ <div ref={refs.setFloating} style={{ ...floatingStyles, zIndex: 60 }}><divid="mention-command"- className="z-50 min-w-[8rem] w-80 rounded-md border bg-popover text-popover-foreground p-1 shadow-md animate-in fade-in-0 zoom-in-95 slide-in-from-top-2 overflow-hidden"+ className="z-50 min-w-32 w-80 rounded-md border bg-popover text-popover-foreground p-1 shadow-md animate-in fade-in-0 zoom-in-95 slide-in-from-top-2 overflow-hidden"><ScrollArea className="h-80"><ScrollViewport ref={scrollContainer}>diff --git a/packages/ui/src/editor/menus/action-menu.tsx b/packages/ui/src/editor/menus/action-menu.tsxindex 431e2533..821c4e78 100644--- a/packages/ui/src/editor/menus/action-menu.tsx+++ b/packages/ui/src/editor/menus/action-menu.tsx@@ -150,7 +150,7 @@ export const ActionMenu = ({ editor }: ActionMenuProps) => {<FloatingPortal><divref={refs.setFloating}- style={floatingStyles}+ style={{ ...floatingStyles, zIndex: 60 }}className="flex items-center text-muted-foreground p-1 mr-2"><Plusdiff --git a/packages/ui/src/editor/views/database.tsx b/packages/ui/src/editor/views/database.tsxindex 6050db79..2cfc05b4 100644--- a/packages/ui/src/editor/views/database.tsx+++ b/packages/ui/src/editor/views/database.tsx@@ -48,15 +48,12 @@ export const DatabaseNodeView = ({ node }: NodeViewProps) => {return (<NodeViewWrapper data-id={node.attrs.id}>- <Link- from="/workspace/$userId"- to="$nodeId"- params={{ nodeId: id }}- className="my-0.5 flex h-10 w-full cursor-pointer flex-row items-center gap-1 rounded-md p-1 hover:bg-accent"- >- <Avatar size="small" id={id} name={name} avatar={avatar} />- <div role="presentation" className="grow">- {name}+ <Link from="/workspace/$userId" to="$nodeId" params={{ nodeId: id }}>+ <div className="my-0.5 flex h-10 w-full cursor-pointer flex-row items-center gap-1 rounded-md p-1 hover:bg-accent">+ <Avatar size="small" id={id} name={name} avatar={avatar} />+ <div role="presentation" className="grow">+ {name}+ </div></div></Link></NodeViewWrapper>diff --git a/packages/ui/src/editor/views/folder.tsx b/packages/ui/src/editor/views/folder.tsxindex 05524832..2fee0619 100644--- a/packages/ui/src/editor/views/folder.tsx+++ b/packages/ui/src/editor/views/folder.tsx@@ -35,15 +35,12 @@ export const FolderNodeView = ({ node }: NodeViewProps) => {return (<NodeViewWrapper data-id={node.attrs.id}>- <Link- from="/workspace/$userId"- to="$nodeId"- params={{ nodeId: id }}- className="my-0.5 flex h-10 w-full cursor-pointer flex-row items-center gap-1 rounded-md p-1 hover:bg-accent"- >- <Avatar size="small" id={id} name={name} avatar={avatar} />- <div role="presentation" className="grow">- {name}+ <Link from="/workspace/$userId" to="$nodeId" params={{ nodeId: id }}>+ <div className="my-0.5 flex h-10 w-full cursor-pointer flex-row items-center gap-1 rounded-md p-1 hover:bg-accent">+ <Avatar size="small" id={id} name={name} avatar={avatar} />+ <div role="presentation" className="grow">+ {name}+ </div></div></Link></NodeViewWrapper>diff --git a/packages/ui/src/editor/views/page.tsx b/packages/ui/src/editor/views/page.tsxindex f6e985ff..36b8235f 100644--- a/packages/ui/src/editor/views/page.tsx+++ b/packages/ui/src/editor/views/page.tsx@@ -35,15 +35,12 @@ export const PageNodeView = ({ node }: NodeViewProps) => {return (<NodeViewWrapper data-id={node.attrs.id}>- <Link- from="/workspace/$userId"- to="$nodeId"- params={{ nodeId: id }}- className="my-0.5 flex h-10 w-full cursor-pointer flex-row items-center gap-1 rounded-md p-1 hover:bg-accent"- >- <Avatar size="small" id={id} name={name} avatar={avatar} />- <div role="presentation" className="grow">- {name}+ <Link from="/workspace/$userId" to="$nodeId" params={{ nodeId: id }}>+ <div className="my-0.5 flex h-10 w-full cursor-pointer flex-row items-center gap-1 rounded-md p-1 hover:bg-accent">+ <Avatar size="small" id={id} name={name} avatar={avatar} />+ <div role="presentation" className="grow">+ {name}+ </div></div></Link></NodeViewWrapper>