Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/components/databrowser/components/databrowser-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { IconPlus } from "@tabler/icons-react"
import { Button } from "@/components/ui/button"
import type { TabId } from "@/store"
import { useDatabrowserStore } from "@/store"
import { TabIdProvider } from "@/tab-provider"
import { IconPlus } from "@tabler/icons-react"

import { Button } from "@/components/ui/button"

import { Tab } from "./tab"

export const DatabrowserTabs = () => {
const { tabs, addTab } = useDatabrowserStore()
const { tabs, addTab, selectedTab } = useDatabrowserStore()

return (
<div className="relative mb-2 shrink-0">
<div className="absolute bottom-0 left-0 right-0 -z-10 h-[1px] w-full bg-zinc-200" />

<div className="scrollbar-hide flex translate-y-[1px] items-center gap-1 overflow-x-scroll pb-[1px] [&::-webkit-scrollbar]:hidden">
{tabs.map(([id]) => (
<TabIdProvider key={id} value={id as TabId}>
<Tab id={id} />
</TabIdProvider>
))}
{selectedTab &&
tabs.map(([id]) => (
<TabIdProvider key={id} value={id as TabId}>
<Tab id={id} />
</TabIdProvider>
))}
<Button
variant="secondary"
size="icon-sm"
Expand Down
7 changes: 5 additions & 2 deletions src/components/databrowser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ export const RedisBrowser = ({
}

const DatabrowserInstances = () => {
const { tabs, selectedTab, addTab } = useDatabrowserStore()
const { tabs, selectedTab, selectTab, addTab } = useDatabrowserStore()

useEffect(() => {
if (tabs.length === 0) addTab()
}, [tabs])
else if (!selectedTab) selectTab(tabs[0][0])
}, [tabs, selectedTab, addTab, selectTab])

if (!selectedTab) return

return tabs.map(([id]) => (
<TabIdProvider key={id} value={id as TabId}>
Expand Down
4 changes: 3 additions & 1 deletion src/tab-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createContext, useContext, useMemo } from "react"

import type { SearchFilter, SelectedItem } from "./store"
import { useDatabrowserStore, type TabId } from "./store"
import type { DataType } from "./types"
Expand Down Expand Up @@ -30,7 +31,8 @@ export const useTab = () => {
const tabId = useTabId()
const tabData = useMemo(() => tabs.find(([id]) => id === tabId)?.[1], [tabs, tabId])

if (!selectedTab || !tabData) throw new Error("selectedTab is undefined when using useTab()")
if (!selectedTab) throw new Error("selectedTab is undefined when using useTab()")
if (!tabData) throw new Error("tabData is undefined when using useTab()")

return useMemo(
() => ({
Expand Down