# All files / src/store selectors.ts

0% Statements 0/43
0% Branches 0/1
0% Functions 0/1
0% Lines 0/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44

     import { createSelector } from '@reduxjs/toolkit'
    import { RootState } from './index'

    export const selectSnippets = (state: RootState) => state.snippets.items
    export const selectSnippetsLoading = (state: RootState) => state.snippets.loading
    export const selectSelectionMode = (state: RootState) => state.snippets.selectionMode
    export const selectSelectedIds = (state: RootState) => state.snippets.selectedIds

    export const selectNamespaces = (state: RootState) => state.namespaces.items
    export const selectSelectedNamespaceId = (state: RootState) => state.namespaces.selectedId
    export const selectNamespacesLoading = (state: RootState) => state.namespaces.loading

    export const selectSearchQuery = (state: RootState) => state.ui.searchQuery
    export const selectDialogOpen = (state: RootState) => state.ui.dialogOpen
    export const selectViewerOpen = (state: RootState) => state.ui.viewerOpen
    export const selectEditingSnippet = (state: RootState) => state.ui.editingSnippet
    export const selectViewingSnippet = (state: RootState) => state.ui.viewingSnippet

    export const selectSelectedNamespace = createSelector(
      [selectNamespaces, selectSelectedNamespaceId],
      (namespaces, selectedId) => namespaces.find(n => n.id === selectedId)
    )

    export const selectFilteredSnippets = createSelector(
      [selectSnippets, selectSearchQuery],
      (snippets, query) => {
        if (!query.trim()) return snippets

        const lowerQuery = query.toLowerCase()
        return snippets.filter(
          (snippet) =>
            snippet.title.toLowerCase().includes(lowerQuery) ||
            snippet.description.toLowerCase().includes(lowerQuery) ||
            snippet.language.toLowerCase().includes(lowerQuery) ||
            snippet.code.toLowerCase().includes(lowerQuery)
        )
      }
    )

    export const selectSelectedSnippets = createSelector(
      [selectSnippets, selectSelectedIds],
      (snippets, selectedIds) => snippets.filter(s => selectedIds.includes(s.id))
    )