feat: use search params for filters instead of redux

This commit is contained in:
2024-01-01 15:17:05 +01:00
parent dd9cc3e3aa
commit a56ca779fc
29 changed files with 247 additions and 110 deletions

View File

@@ -8,6 +8,7 @@ import {
baseApi,
} from '@/services'
import { RootState } from '@/services/store'
import { getValuable } from '@/utils'
const decksService = baseApi.injectEndpoints({
endpoints: builder => ({
@@ -16,13 +17,10 @@ const decksService = baseApi.injectEndpoints({
async onQueryStarted(_, { dispatch, getState, queryFulfilled }) {
const res = await queryFulfilled
console.log(decksService.util.selectCachedArgsForQuery(getState(), 'getDecks'))
for (const { endpointName, originalArgs } of decksService.util.selectInvalidatedBy(
getState(),
[{ type: 'Decks' }]
)) {
console.log(endpointName, originalArgs)
// we only want to update `getPosts` here
if (endpointName !== 'getDecks') {
continue
}
@@ -32,31 +30,6 @@ const decksService = baseApi.injectEndpoints({
})
)
}
// console.log(args)
// const minCardsCount = state.decks.minCards
// const search = state.decks.search
// const currentPage = state.decks.currentPage
// const maxCardsCount = state.decks.maxCards
// const authorId = state.decks.authorId
//
// console.log(res)
//
// dispatch(
// decksService.util.updateQueryData(
// 'getDecks',
// {
// authorId,
// currentPage,
// maxCardsCount,
// minCardsCount,
// name: search,
// },
// draft => {
// draft.items.unshift(res.data)
// }
// )
// )
},
query: body => ({
body,
@@ -81,7 +54,7 @@ const decksService = baseApi.injectEndpoints({
providesTags: ['Decks'],
query: args => {
return {
params: args ?? undefined,
params: args ? getValuable(args) : undefined,
url: `v1/decks`,
}
},
@@ -91,7 +64,6 @@ const decksService = baseApi.injectEndpoints({
async onQueryStarted({ id, ...patch }, { dispatch, getState, queryFulfilled }) {
const state = getState() as RootState
console.log(state)
const minCardsCount = state.decks.minCards
const search = state.decks.search
const currentPage = state.decks.currentPage

View File

@@ -54,13 +54,13 @@ export type Card = {
}
export type GetDecksArgs = {
authorId?: string
currentPage?: number
itemsPerPage?: number
maxCardsCount?: number
minCardsCount?: number
name?: string
orderBy?: string
authorId?: null | string
currentPage?: null | number
itemsPerPage?: null | number
maxCardsCount?: null | number
minCardsCount?: null | number
name?: null | string
orderBy?: null | string
}
export type CreateDeckArgs = {

View File

@@ -1,10 +1,11 @@
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
import { baseApi } from './base-api'
import { decksSlice } from '@/services/decks/decks.slice'
import { configureStore } from '@reduxjs/toolkit'
import { setupListeners } from '@reduxjs/toolkit/query/react'
import { baseApi } from './base-api'
export const store = configureStore({
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(baseApi.middleware),
reducer: {