Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Sidebar toggle #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 27 additions & 10 deletions src/screens/Snippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ export const Snippets = () => {
}
}

const toggleSidebar = () => {
actions.toggleSidebar(state.isSidebarCollapsed);
}

createEffect(() => {
if (getSearchType()) {
searchInputEl?.focus()
Expand Down Expand Up @@ -256,10 +260,9 @@ export const Snippets = () => {
<div class="h-screen" classList={{ "is-mac": state.isMac }}>
<div class="h-main flex">
<div
class="border-r w-64 shrink-0 h-full flex flex-col"
classList={{ "show-search": getSearchType() !== null }}
>
<div class="sidebar-header text-zinc-500 dark:text-zinc-300 text-xs">
class="shrink-0 h-full flex flex-col h-full"
classList={{ "show-search": getSearchType() !== null, "w-10": state.isSidebarCollapsed, "w-64": !state.isSidebarCollapsed}}>
<div class="sidebar-header text-zinc-500 dark:text-zinc-300 text-xs" classList={{"invisible": state.isSidebarCollapsed}}>
<Show when={state.isMac}>
<div class="h-6" data-tauri-drag-region></div>
</Show>
Expand Down Expand Up @@ -293,7 +296,7 @@ export const Snippets = () => {
}
setSearchType("non-trash")
}}
tooltip={{ content: "Show search box" }}
tooltip={{ content: "Search" }}
isActive={getSearchType() === "non-trash"}
></Button>
<Button
Expand Down Expand Up @@ -351,7 +354,7 @@ export const Snippets = () => {
</div>
</Show>
</div>
<div class="sidebar-body group/sidebar-body flex-1 overflow-y-auto custom-scrollbar scrollbar-group p-2 pt-0 space-y-1">
<div class="sidebar-body group/sidebar-body flex-1 overflow-y-auto custom-scrollbar scrollbar-group p-2 pt-0 space-y-1" classList={{"invisible": state.isSidebarCollapsed}}>
<For each={snippets()}>
{(snippet) => {
return (
Expand Down Expand Up @@ -430,24 +433,38 @@ export const Snippets = () => {
}}
</For>
</div>
{snippet() && <div class="sidebar-footer text-zinc-500 dark:text-zinc-300 text-xs border-t">
<div
data-tauri-drag-region
class="flex items-center justify-end px-2 h-10 shrink-0"
>
<div class="flex items-center">
<Button
type="button"
icon={state.isSidebarCollapsed ? "i-mdi:arrow-collapse-right" : "i-mdi:arrow-collapse-left"}
tooltip={{content: "Toggle sidebar"}}
onClick={() => toggleSidebar()}
></Button>
</div>
</div>
</div>}
</div>
<Show
when={snippet()}
fallback={
<div
data-tauri-drag-region
class="h-full w-full flex items-center justify-center px-20 text-center text-zinc-400 text-xl"
class="h-full w-full flex items-center justify-center px-20 text-center text-zinc-400 text-xl border-l"
>
<span class="select-none">
Select or create a snippet from sidebar
</span>
</div>
}
>
<div class="w-full h-full">
<div data-tauri-drag-region class="w-full h-full pt-6">
<div
data-tauri-drag-region
class="border-b flex h-mainHeader items-center px-3 justify-between space-x-3"
class="border-l border-b border-t flex h-mainHeader items-center px-3 justify-between space-x-3"
>
<input
value={nameInputControl.value}
Expand Down
6 changes: 6 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const [state, setState] = createStore<{
folder: string | null
snippets: Snippet[]
isMac: boolean
isSidebarCollapsed: boolean
}>({
ready: false,
app: {
Expand All @@ -33,6 +34,7 @@ const [state, setState] = createStore<{
folder: null,
snippets: [],
isMac: /macintosh/i.test(navigator.userAgent),
isSidebarCollapsed: false
})

export { state }
Expand Down Expand Up @@ -291,4 +293,8 @@ export const actions = {
{ dir: BaseDirectory.Data }
)
},

toggleSidebar: (isSidebarCollapsed: boolean) => {
setState("isSidebarCollapsed", !isSidebarCollapsed)
},
}