Generated by Spark: I moved a card, which works fine, but Redux doesnt react, which is weird as Redux is really good at this.

This commit is contained in:
2026-01-17 21:15:59 +00:00
committed by GitHub
parent fdd0120994
commit eb26000020
2 changed files with 22 additions and 5 deletions

View File

@@ -29,6 +29,7 @@ import {
createSnippet,
updateSnippet,
deleteSnippet,
moveSnippet,
toggleSelectionMode,
toggleSnippetSelection,
selectAllSnippets as selectAllSnippetsAction,
@@ -142,6 +143,12 @@ export function SnippetManagerRedux() {
dispatch(openViewer(snippet))
}, [dispatch])
const handleMoveSnippet = useCallback(async () => {
if (selectedNamespaceId) {
dispatch(fetchSnippetsByNamespace(selectedNamespaceId))
}
}, [dispatch, selectedNamespaceId])
const handleCreateNew = useCallback(() => {
dispatch(openDialog(null))
}, [dispatch])
@@ -401,6 +408,7 @@ export function SnippetManagerRedux() {
onEdit={handleEditSnippet}
onDelete={handleDeleteSnippet}
onCopy={handleCopyCode}
onMove={handleMoveSnippet}
selectionMode={selectionMode}
isSelected={selectedIds.includes(snippet.id)}
onToggleSelect={handleToggleSnippetSelection}

View File

@@ -7,6 +7,7 @@ import {
deleteSnippet as deleteSnippetDB,
getSnippetsByNamespace,
bulkMoveSnippets as bulkMoveSnippetsDB,
moveSnippetToNamespace,
} from '@/lib/db'
interface SnippetsState {
@@ -73,6 +74,14 @@ export const deleteSnippet = createAsyncThunk(
}
)
export const moveSnippet = createAsyncThunk(
'snippets/move',
async ({ snippetId, targetNamespaceId }: { snippetId: string, targetNamespaceId: string }) => {
await moveSnippetToNamespace(snippetId, targetNamespaceId)
return { snippetId, targetNamespaceId }
}
)
export const bulkMoveSnippets = createAsyncThunk(
'snippets/bulkMove',
async ({ snippetIds, targetNamespaceId }: { snippetIds: string[], targetNamespaceId: string }) => {
@@ -144,13 +153,13 @@ const snippetsSlice = createSlice({
.addCase(deleteSnippet.fulfilled, (state, action) => {
state.items = state.items.filter(s => s.id !== action.payload)
})
.addCase(moveSnippet.fulfilled, (state, action) => {
const { snippetId, targetNamespaceId } = action.payload
state.items = state.items.filter(s => s.id !== snippetId)
})
.addCase(bulkMoveSnippets.fulfilled, (state, action) => {
const { snippetIds, targetNamespaceId } = action.payload
state.items.forEach(snippet => {
if (snippetIds.includes(snippet.id)) {
snippet.namespaceId = targetNamespaceId
}
})
state.items = state.items.filter(s => !snippetIds.includes(s.id))
state.selectedIds = []
state.selectionMode = false
})