Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
refactor(snippets): replace snippets handling with computed displayed…
…Snippets
  • Loading branch information
antonreshetov committed Mar 18, 2025
commit 47a59de8f35f3299e17618e6cface8c5865992e4
19 changes: 11 additions & 8 deletions src/renderer/components/snippet/List.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import type { SnippetsQuery } from '@/services/api/generated'
import { ScrollArea } from '@/components/ui/shadcn/scroll-area'
import { useApp, useGutter, useSnippets } from '@/composables'
import { LibraryFilter } from '@/composables/types'
import { store } from '@/electron'
Expand All @@ -10,7 +11,7 @@ const gutterRef = ref<{ $el: HTMLElement }>()

const { snippetListWidth, sidebarWidth, selectedFolderId, selectedLibrary }
= useApp()
const { snippets, snippetsBySearch, isSearch, getSnippets } = useSnippets()
const { displayedSnippets, getSnippets } = useSnippets()

async function initGetSnippets() {
const query: SnippetsQuery = {}
Expand Down Expand Up @@ -67,13 +68,15 @@ watch(width, () => {
<div>
<SnippetHeader />
</div>
<div class="flex-grow overflow-y-auto">
<SnippetItem
v-for="snippet in isSearch ? snippetsBySearch : snippets"
:key="snippet.id"
:snippet="snippet"
/>
</div>
<ScrollArea>
<div class="flex-grow overflow-y-auto">
<SnippetItem
v-for="snippet in displayedSnippets"
:key="snippet.id"
:snippet="snippet"
/>
</div>
</ScrollArea>
<UiGutter ref="gutterRef" />
</div>
</template>
11 changes: 9 additions & 2 deletions src/renderer/composables/useSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const snippetsBySearch = shallowRef<SnippetsResponse>()
const searchQuery = ref('')
const isSearch = ref(false)

const displayedSnippets = computed(() => {
if (isSearch.value) {
return snippetsBySearch.value
}

return snippets.value
})

const selectedSnippet = computed(() => {
if (isSearch.value) {
return snippetsBySearch.value?.find(
Expand Down Expand Up @@ -220,6 +228,7 @@ export function useSnippets() {
createSnippetContent,
deleteSnippet,
deleteSnippetContent,
displayedSnippets,
duplicateSnippet,
getSnippets,
isEmpty,
Expand All @@ -229,8 +238,6 @@ export function useSnippets() {
selectedSnippetContent,
selectFirstSnippet,
selectSnippet,
snippets,
snippetsBySearch,
updateSnippet,
updateSnippetContent,
}
Expand Down