mirror of
https://github.com/johndoe6345789/snippet-pastebin.git
synced 2026-04-24 13:34:55 +00:00
Generated by Spark: Redux should be reactive, but its not being fully reactive. Is redux set up properly in package.json?
This commit is contained in:
@@ -182,15 +182,15 @@ export function SnippetManagerRedux() {
|
||||
}, [dispatch])
|
||||
|
||||
const handleSelectAll = useCallback(() => {
|
||||
if (selectedIds.size === filteredSnippets.length) {
|
||||
if (selectedIds.length === filteredSnippets.length) {
|
||||
dispatch(clearSelection())
|
||||
} else {
|
||||
dispatch(selectAllSnippetsAction())
|
||||
}
|
||||
}, [dispatch, filteredSnippets.length, selectedIds.size])
|
||||
}, [dispatch, filteredSnippets.length, selectedIds.length])
|
||||
|
||||
const handleBulkMove = useCallback(async (targetNamespaceId: string) => {
|
||||
if (selectedIds.size === 0) {
|
||||
if (selectedIds.length === 0) {
|
||||
toast.error('No snippets selected')
|
||||
return
|
||||
}
|
||||
@@ -202,7 +202,7 @@ export function SnippetManagerRedux() {
|
||||
})).unwrap()
|
||||
|
||||
const targetNamespace = namespaces.find(n => n.id === targetNamespaceId)
|
||||
toast.success(`Moved ${selectedIds.size} snippet${selectedIds.size > 1 ? 's' : ''} to ${targetNamespace?.name || 'namespace'}`)
|
||||
toast.success(`Moved ${selectedIds.length} snippet${selectedIds.length > 1 ? 's' : ''} to ${targetNamespace?.name || 'namespace'}`)
|
||||
|
||||
if (selectedNamespaceId) {
|
||||
dispatch(fetchSnippetsByNamespace(selectedNamespaceId))
|
||||
@@ -355,12 +355,12 @@ export function SnippetManagerRedux() {
|
||||
size="sm"
|
||||
onClick={handleSelectAll}
|
||||
>
|
||||
{selectedIds.size === filteredSnippets.length ? 'Deselect All' : 'Select All'}
|
||||
{selectedIds.length === filteredSnippets.length ? 'Deselect All' : 'Select All'}
|
||||
</Button>
|
||||
{selectedIds.size > 0 && (
|
||||
{selectedIds.length > 0 && (
|
||||
<>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{selectedIds.size} selected
|
||||
{selectedIds.length} selected
|
||||
</span>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -402,7 +402,7 @@ export function SnippetManagerRedux() {
|
||||
onDelete={handleDeleteSnippet}
|
||||
onCopy={handleCopyCode}
|
||||
selectionMode={selectionMode}
|
||||
isSelected={selectedIds.has(snippet.id)}
|
||||
isSelected={selectedIds.includes(snippet.id)}
|
||||
onToggleSelect={handleToggleSnippetSelection}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -11,9 +11,7 @@ export const store = configureStore({
|
||||
ui: uiReducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware({
|
||||
serializableCheck: false,
|
||||
}).concat(persistenceMiddleware),
|
||||
getDefaultMiddleware().concat(persistenceMiddleware),
|
||||
devTools: {
|
||||
name: 'CodeSnippet',
|
||||
trace: true,
|
||||
|
||||
@@ -39,5 +39,5 @@ export const selectFilteredSnippets = createSelector(
|
||||
|
||||
export const selectSelectedSnippets = createSelector(
|
||||
[selectSnippets, selectSelectedIds],
|
||||
(snippets, selectedIds) => snippets.filter(s => selectedIds.has(s.id))
|
||||
(snippets, selectedIds) => snippets.filter(s => selectedIds.includes(s.id))
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ interface SnippetsState {
|
||||
items: Snippet[]
|
||||
loading: boolean
|
||||
error: string | null
|
||||
selectedIds: Set<string>
|
||||
selectedIds: string[]
|
||||
selectionMode: boolean
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ const initialState: SnippetsState = {
|
||||
items: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
selectedIds: new Set(),
|
||||
selectedIds: [],
|
||||
selectionMode: false,
|
||||
}
|
||||
|
||||
@@ -88,23 +88,22 @@ const snippetsSlice = createSlice({
|
||||
toggleSelectionMode: (state) => {
|
||||
state.selectionMode = !state.selectionMode
|
||||
if (!state.selectionMode) {
|
||||
state.selectedIds = new Set()
|
||||
state.selectedIds = []
|
||||
}
|
||||
},
|
||||
toggleSnippetSelection: (state, action: PayloadAction<string>) => {
|
||||
const newSet = new Set(state.selectedIds)
|
||||
if (newSet.has(action.payload)) {
|
||||
newSet.delete(action.payload)
|
||||
const index = state.selectedIds.indexOf(action.payload)
|
||||
if (index !== -1) {
|
||||
state.selectedIds.splice(index, 1)
|
||||
} else {
|
||||
newSet.add(action.payload)
|
||||
state.selectedIds.push(action.payload)
|
||||
}
|
||||
state.selectedIds = newSet
|
||||
},
|
||||
clearSelection: (state) => {
|
||||
state.selectedIds = new Set()
|
||||
state.selectedIds = []
|
||||
},
|
||||
selectAllSnippets: (state) => {
|
||||
state.selectedIds = new Set(state.items.map(s => s.id))
|
||||
state.selectedIds = state.items.map(s => s.id)
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
@@ -152,7 +151,7 @@ const snippetsSlice = createSlice({
|
||||
snippet.namespaceId = targetNamespaceId
|
||||
}
|
||||
})
|
||||
state.selectedIds = new Set()
|
||||
state.selectedIds = []
|
||||
state.selectionMode = false
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user