Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Rename 'id' to 'path' for container tab data

Hakan Shehue34ca6744068
diff --git a/apps/desktop/src/renderer/components/layouts/containers/container-tab-content.tsx b/apps/desktop/src/renderer/components/layouts/containers/container-tab-content.tsx
index dd5a51ea..670c5749 100644
--- a/apps/desktop/src/renderer/components/layouts/containers/container-tab-content.tsx
+++ b/apps/desktop/src/renderer/components/layouts/containers/container-tab-content.tsx
@@ -18,18 +18,20 @@ interface ContainerTabContentProps {
export const ContainerTabContent = ({ tab }: ContainerTabContentProps) => {
return (
<TabsContent
- value={tab.id}
- key={tab.id}
+ value={tab.path}
+ key={tab.path}
className="h-full min-h-full w-full min-w-full m-0 pt-2"
>
- {match(getIdType(tab.id))
- .with(IdType.Channel, () => <ChannelContainer channelId={tab.id} />)
- .with(IdType.Page, () => <PageContainer pageId={tab.id} />)
- .with(IdType.Database, () => <DatabaseContainer databaseId={tab.id} />)
- .with(IdType.Record, () => <RecordContainer recordId={tab.id} />)
- .with(IdType.Chat, () => <ChatContainer chatId={tab.id} />)
- .with(IdType.Folder, () => <FolderContainer folderId={tab.id} />)
- .with(IdType.File, () => <FileContainer fileId={tab.id} />)
+ {match(getIdType(tab.path))
+ .with(IdType.Channel, () => <ChannelContainer channelId={tab.path} />)
+ .with(IdType.Page, () => <PageContainer pageId={tab.path} />)
+ .with(IdType.Database, () => (
+ <DatabaseContainer databaseId={tab.path} />
+ ))
+ .with(IdType.Record, () => <RecordContainer recordId={tab.path} />)
+ .with(IdType.Chat, () => <ChatContainer chatId={tab.path} />)
+ .with(IdType.Folder, () => <FolderContainer folderId={tab.path} />)
+ .with(IdType.File, () => <FileContainer fileId={tab.path} />)
.otherwise(() => null)}
</TabsContent>
);
diff --git a/apps/desktop/src/renderer/components/layouts/containers/container-tab-trigger.tsx b/apps/desktop/src/renderer/components/layouts/containers/container-tab-trigger.tsx
index 485cb627..d47c8f30 100644
--- a/apps/desktop/src/renderer/components/layouts/containers/container-tab-trigger.tsx
+++ b/apps/desktop/src/renderer/components/layouts/containers/container-tab-trigger.tsx
@@ -28,7 +28,7 @@ export const ContainerTabTrigger = ({
}: ContainerTabTriggerProps) => {
const [, dragRef] = useDrag<string>({
type: 'container-tab',
- item: tab.id,
+ item: tab.path,
canDrag: () => true,
end: (_item, monitor) => {
const dropResult = monitor.getDropResult<{ before: string | null }>();
@@ -46,7 +46,7 @@ export const ContainerTabTrigger = ({
const [dropMonitor, dropRef] = useDrop({
accept: 'container-tab',
drop: () => ({
- before: tab.id,
+ before: tab.path,
}),
collect: (monitor) => ({
isOver: monitor.isOver(),
@@ -59,8 +59,8 @@ export const ContainerTabTrigger = ({
return (
<TabsTrigger
- value={tab.id}
- key={tab.id}
+ value={tab.path}
+ key={tab.path}
className={cn(
'overflow-hidden rounded-b-none bg-muted py-2 data-[state=active]:z-10 data-[state=active]:shadow-none h-10 group/tab app-no-drag-region flex items-center justify-between gap-2',
tab.preview && 'italic',
@@ -77,18 +77,18 @@ export const ContainerTabTrigger = ({
ref={dragDropRef as React.LegacyRef<HTMLButtonElement>}
>
<div className="overflow-hidden truncate">
- {match(getIdType(tab.id))
+ {match(getIdType(tab.path))
.with(IdType.Channel, () => (
- <ChannelContainerTab channelId={tab.id} />
+ <ChannelContainerTab channelId={tab.path} />
))
- .with(IdType.Page, () => <PageContainerTab pageId={tab.id} />)
+ .with(IdType.Page, () => <PageContainerTab pageId={tab.path} />)
.with(IdType.Database, () => (
- <DatabaseContainerTab databaseId={tab.id} />
+ <DatabaseContainerTab databaseId={tab.path} />
))
- .with(IdType.Record, () => <RecordContainerTab recordId={tab.id} />)
- .with(IdType.Chat, () => <ChatContainerTab chatId={tab.id} />)
- .with(IdType.Folder, () => <FolderContainerTab folderId={tab.id} />)
- .with(IdType.File, () => <FileContainerTab fileId={tab.id} />)
+ .with(IdType.Record, () => <RecordContainerTab recordId={tab.path} />)
+ .with(IdType.Chat, () => <ChatContainerTab chatId={tab.path} />)
+ .with(IdType.Folder, () => <FolderContainerTab folderId={tab.path} />)
+ .with(IdType.File, () => <FileContainerTab fileId={tab.path} />)
.otherwise(() => null)}
</div>
<div
diff --git a/apps/desktop/src/renderer/components/layouts/containers/container-tabs.tsx b/apps/desktop/src/renderer/components/layouts/containers/container-tabs.tsx
index 6df9c0d0..7cb780d1 100644
--- a/apps/desktop/src/renderer/components/layouts/containers/container-tabs.tsx
+++ b/apps/desktop/src/renderer/components/layouts/containers/container-tabs.tsx
@@ -23,7 +23,7 @@ export const ContainerTabs = ({
onClose,
onMove,
}: ContainerTabsProps) => {
- const activeTab = tabs.find((t) => t.active)?.id;
+ const activeTab = tabs.find((t) => t.active)?.path;
const [dropMonitor, dropRef] = useDrop({
accept: 'container-tab',
@@ -41,7 +41,7 @@ export const ContainerTabs = ({
return (
<Tabs
- defaultValue={tabs[0]?.id}
+ defaultValue={tabs[0]?.path}
value={activeTab}
onValueChange={onTabChange}
onFocus={onFocus}
@@ -51,10 +51,10 @@ export const ContainerTabs = ({
<TabsList className="h-10 bg-slate-50 w-full justify-start p-0 app-drag-region">
{tabs.map((tab) => (
<ContainerTabTrigger
- key={tab.id}
+ key={tab.path}
tab={tab}
- onClose={() => onClose(tab.id)}
- onMove={(before) => onMove(tab.id, before)}
+ onClose={() => onClose(tab.path)}
+ onMove={(before) => onMove(tab.path, before)}
/>
))}
<div
@@ -71,7 +71,7 @@ export const ContainerTabs = ({
</ScrollArea>
<div className="flex-grow overflow-hidden">
{tabs.map((tab) => (
- <ContainerTabContent key={tab.id} tab={tab} />
+ <ContainerTabContent key={tab.path} tab={tab} />
))}
</div>
</Tabs>
diff --git a/apps/desktop/src/renderer/components/layouts/layout.tsx b/apps/desktop/src/renderer/components/layouts/layout.tsx
index 9fd8a756..5986973c 100644
--- a/apps/desktop/src/renderer/components/layouts/layout.tsx
+++ b/apps/desktop/src/renderer/components/layouts/layout.tsx
@@ -53,8 +53,8 @@ export const Layout = () => {
previewRight: handlePreviewRight,
activeTab:
activeContainer === 'left'
- ? leftContainerMetadata.tabs.find((t) => t.active)?.id
- : rightContainerMetadata.tabs.find((t) => t.active)?.id,
+ ? leftContainerMetadata.tabs.find((t) => t.active)?.path
+ : rightContainerMetadata.tabs.find((t) => t.active)?.path,
}}
>
<div className="w-screen min-w-screen h-screen min-h-screen flex flex-row">
diff --git a/apps/desktop/src/renderer/hooks/user-layout-state.tsx b/apps/desktop/src/renderer/hooks/user-layout-state.tsx
index acb0d373..3aebea3e 100644
--- a/apps/desktop/src/renderer/hooks/user-layout-state.tsx
+++ b/apps/desktop/src/renderer/hooks/user-layout-state.tsx
@@ -105,15 +105,18 @@ export const useLayoutState = () => {
);
const handleOpenLeft = useCallback(
- (tab: string) => {
- const existingTab = leftContainerMetadata.tabs.find((t) => t.id === tab);
+ (path: string) => {
+ const existingTab = leftContainerMetadata.tabs.find(
+ (t) => t.path === path
+ );
+
if (existingTab) {
replaceLeftContainerMetadata({
...leftContainerMetadata,
tabs: leftContainerMetadata.tabs.map((t) => ({
...t,
- active: t.id === tab ? true : undefined,
- preview: t.id === tab ? undefined : t.preview,
+ active: t.path === path ? true : undefined,
+ preview: t.path === path ? undefined : t.preview,
})),
});
} else {
@@ -121,12 +124,12 @@ export const useLayoutState = () => {
...leftContainerMetadata,
tabs: [
...leftContainerMetadata.tabs
- .filter((t) => t.id !== tab)
+ .filter((t) => t.path !== path)
.map((t) => ({
...t,
active: undefined,
})),
- { id: tab, active: true },
+ { path, active: true },
],
});
}
@@ -135,15 +138,18 @@ export const useLayoutState = () => {
);
const handleOpenRight = useCallback(
- (tab: string) => {
- const existingTab = rightContainerMetadata.tabs.find((t) => t.id === tab);
+ (path: string) => {
+ const existingTab = rightContainerMetadata.tabs.find(
+ (t) => t.path === path
+ );
+
if (existingTab) {
replaceRightContainerMetadata({
...rightContainerMetadata,
tabs: rightContainerMetadata.tabs.map((t) => ({
...t,
- active: t.id === tab ? true : undefined,
- preview: t.id === tab ? undefined : t.preview,
+ active: t.path === path ? true : undefined,
+ preview: t.path === path ? undefined : t.preview,
})),
});
} else {
@@ -151,12 +157,12 @@ export const useLayoutState = () => {
...rightContainerMetadata,
tabs: [
...rightContainerMetadata.tabs
- .filter((t) => t.id !== tab)
+ .filter((t) => t.path !== path)
.map((t) => ({
...t,
active: undefined,
})),
- { id: tab, active: true },
+ { path, active: true },
],
});
}
@@ -165,27 +171,27 @@ export const useLayoutState = () => {
);
const handleOpen = useCallback(
- (tab: string) => {
+ (path: string) => {
if (activeContainer === 'left') {
- handleOpenLeft(tab);
+ handleOpenLeft(path);
} else {
- handleOpenRight(tab);
+ handleOpenRight(path);
}
},
[activeContainer, handleOpenLeft, handleOpenRight]
);
const handleCloseLeft = useCallback(
- (tab: string) => {
+ (path: string) => {
const existingTabIndex = leftContainerMetadata.tabs.findIndex(
- (t) => t.id === tab
+ (t) => t.path === path
);
if (existingTabIndex === -1) {
return;
}
- const newTabs = leftContainerMetadata.tabs.filter((t) => t.id !== tab);
+ const newTabs = leftContainerMetadata.tabs.filter((t) => t.path !== path);
// Make the closest tab active, preferring the previous tab
if (newTabs.length > 0 && !newTabs.some((t) => t.active)) {
@@ -195,7 +201,7 @@ export const useLayoutState = () => {
newTabs[0];
newTabs.forEach((t) => {
- t.active = t.id === nextActiveTab?.id;
+ t.active = t.path === nextActiveTab?.path;
});
}
@@ -224,16 +230,18 @@ export const useLayoutState = () => {
);
const handleCloseRight = useCallback(
- (tab: string) => {
+ (path: string) => {
const existingTabIndex = rightContainerMetadata.tabs.findIndex(
- (t) => t.id === tab
+ (t) => t.path === path
);
if (existingTabIndex === -1) {
return;
}
- const newTabs = rightContainerMetadata.tabs.filter((t) => t.id !== tab);
+ const newTabs = rightContainerMetadata.tabs.filter(
+ (t) => t.path !== path
+ );
// Make the closest tab active, preferring the previous tab
if (newTabs.length > 0 && !newTabs.some((t) => t.active)) {
@@ -243,7 +251,7 @@ export const useLayoutState = () => {
newTabs[0];
newTabs.forEach((t) => {
- t.active = t.id === nextActiveTab?.id;
+ t.active = t.path === nextActiveTab?.path;
});
}
@@ -260,23 +268,25 @@ export const useLayoutState = () => {
);
const handleClose = useCallback(
- (tab: string) => {
- handleCloseLeft(tab);
- handleCloseRight(tab);
+ (path: string) => {
+ handleCloseLeft(path);
+ handleCloseRight(path);
},
[handleCloseLeft, handleCloseRight]
);
const handlePreviewLeft = useCallback(
- (tab: string, keepCurrent: boolean = false) => {
- const existingTab = leftContainerMetadata.tabs.find((t) => t.id === tab);
+ (path: string, keepCurrent: boolean = false) => {
+ const existingTab = leftContainerMetadata.tabs.find(
+ (t) => t.path === path
+ );
if (existingTab) {
if (!existingTab.active) {
replaceLeftContainerMetadata({
...leftContainerMetadata,
tabs: leftContainerMetadata.tabs.map((t) => ({
...t,
- active: t.id === tab ? true : undefined,
+ active: t.path === path ? true : undefined,
})),
});
}
@@ -294,7 +304,7 @@ export const useLayoutState = () => {
active: undefined,
preview: undefined,
})),
- { id: tab, active: true, preview: true },
+ { path, active: true, preview: true },
],
});
},
@@ -302,15 +312,18 @@ export const useLayoutState = () => {
);
const handlePreviewRight = useCallback(
- (tab: string, keepCurrent: boolean = false) => {
- const existingTab = rightContainerMetadata.tabs.find((t) => t.id === tab);
+ (path: string, keepCurrent: boolean = false) => {
+ const existingTab = rightContainerMetadata.tabs.find(
+ (t) => t.path === path
+ );
+
if (existingTab) {
if (!existingTab.active) {
replaceRightContainerMetadata({
...rightContainerMetadata,
tabs: rightContainerMetadata.tabs.map((t) => ({
...t,
- active: t.id === tab ? true : undefined,
+ active: t.path === path ? true : undefined,
})),
});
}
@@ -328,7 +341,7 @@ export const useLayoutState = () => {
active: undefined,
preview: true,
})),
- { id: tab, active: true, preview: true },
+ { path, active: true, preview: true },
],
});
},
@@ -336,19 +349,19 @@ export const useLayoutState = () => {
);
const handlePreview = useCallback(
- (tab: string, keepCurrent: boolean = false) => {
+ (path: string, keepCurrent: boolean = false) => {
if (activeContainer === 'left') {
- handlePreviewLeft(tab, keepCurrent);
+ handlePreviewLeft(path, keepCurrent);
} else {
- handlePreviewRight(tab, keepCurrent);
+ handlePreviewRight(path, keepCurrent);
}
},
[activeContainer, handlePreviewLeft, handlePreviewRight]
);
const handleActivateLeft = useCallback(
- (tab: string) => {
- if (!leftContainerMetadata.tabs.some((t) => t.id === tab)) {
+ (path: string) => {
+ if (!leftContainerMetadata.tabs.some((t) => t.path === path)) {
return;
}
@@ -356,7 +369,7 @@ export const useLayoutState = () => {
...leftContainerMetadata,
tabs: leftContainerMetadata.tabs.map((t) => ({
...t,
- active: t.id === tab ? true : undefined,
+ active: t.path === path ? true : undefined,
})),
});
},
@@ -364,8 +377,8 @@ export const useLayoutState = () => {
);
const handleActivateRight = useCallback(
- (tab: string) => {
- if (!rightContainerMetadata.tabs.some((t) => t.id === tab)) {
+ (path: string) => {
+ if (!rightContainerMetadata.tabs.some((t) => t.path === path)) {
return;
}
@@ -373,7 +386,7 @@ export const useLayoutState = () => {
...rightContainerMetadata,
tabs: rightContainerMetadata.tabs.map((t) => ({
...t,
- active: t.id === tab ? true : undefined,
+ active: t.path === path ? true : undefined,
})),
});
},
@@ -381,19 +394,21 @@ export const useLayoutState = () => {
);
const handleActivate = useCallback(
- (tab: string) => {
+ (path: string) => {
if (activeContainer === 'left') {
- handleActivateLeft(tab);
+ handleActivateLeft(path);
} else {
- handleActivateRight(tab);
+ handleActivateRight(path);
}
},
[activeContainer, handleActivateLeft, handleActivateRight]
);
const handleMoveLeft = useCallback(
- (id: string, before: string | null) => {
- const tabIndex = leftContainerMetadata.tabs.findIndex((t) => t.id === id);
+ (path: string, before: string | null) => {
+ const tabIndex = leftContainerMetadata.tabs.findIndex(
+ (t) => t.path === path
+ );
if (tabIndex === -1) {
return;
@@ -415,7 +430,7 @@ export const useLayoutState = () => {
});
} else {
const beforeIndex = leftContainerMetadata.tabs.findIndex(
- (t) => t.id === before
+ (t) => t.path === before
);
if (beforeIndex === -1 || tabIndex === beforeIndex - 1) {
@@ -425,7 +440,7 @@ export const useLayoutState = () => {
const newTabs = [...leftContainerMetadata.tabs];
newTabs.splice(tabIndex, 1);
- const newIndex = newTabs.findIndex((t) => t.id === before);
+ const newIndex = newTabs.findIndex((t) => t.path === before);
newTabs.splice(newIndex, 0, tab);
replaceLeftContainerMetadata({
@@ -438,9 +453,9 @@ export const useLayoutState = () => {
);
const handleMoveRight = useCallback(
- (id: string, before: string | null) => {
+ (path: string, before: string | null) => {
const tabIndex = rightContainerMetadata.tabs.findIndex(
- (t) => t.id === id
+ (t) => t.path === path
);
if (tabIndex === -1) {
@@ -463,7 +478,7 @@ export const useLayoutState = () => {
});
} else {
const beforeIndex = rightContainerMetadata.tabs.findIndex(
- (t) => t.id === before
+ (t) => t.path === before
);
if (beforeIndex === -1 || tabIndex === beforeIndex - 1) {
@@ -473,7 +488,7 @@ export const useLayoutState = () => {
const newTabs = [...rightContainerMetadata.tabs];
newTabs.splice(tabIndex, 1);
- const newIndex = newTabs.findIndex((t) => t.id === before);
+ const newIndex = newTabs.findIndex((t) => t.path === before);
newTabs.splice(newIndex, 0, tab);
replaceRightContainerMetadata({
diff --git a/apps/desktop/src/shared/types/workspaces.ts b/apps/desktop/src/shared/types/workspaces.ts
index c82d65d7..73f805ba 100644
--- a/apps/desktop/src/shared/types/workspaces.ts
+++ b/apps/desktop/src/shared/types/workspaces.ts
@@ -13,7 +13,7 @@ export type Workspace = {
};
export type ContainerTab = {
- id: string;
+ path: string;
preview?: boolean;
active?: boolean;
};