mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-25 05:09:27 +00:00
add modals
This commit is contained in:
@@ -6,7 +6,7 @@ export const selectDecksPerPage = (state: RootState) => state.decks.perPage
|
||||
|
||||
export const selectDecksSearch = (state: RootState) => state.decks.search
|
||||
|
||||
export const selectDecksAuthorId = (state: RootState) => state.decks.authorId
|
||||
export const selectDecksCurrentTab = (state: RootState) => state.decks.currentTab
|
||||
|
||||
export const selectDecksMinCards = (state: RootState) => state.decks.minCards
|
||||
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { CardsResponse, DeckResponse, DecksResponse } from './decks.types'
|
||||
import { CardsResponse, DeckResponse, DecksResponse, GetDecksArgs } from './decks.types'
|
||||
|
||||
import { baseApi } from '@/services'
|
||||
|
||||
const decksService = baseApi.injectEndpoints({
|
||||
endpoints: builder => ({
|
||||
getDecks: builder.query<DecksResponse, void>({
|
||||
query: () => `v1/decks`,
|
||||
getDecks: builder.query<DecksResponse, GetDecksArgs | void>({
|
||||
query: args => {
|
||||
return {
|
||||
url: `v1/decks`,
|
||||
params: args ?? undefined,
|
||||
}
|
||||
},
|
||||
}),
|
||||
getDeckById: builder.query<DeckResponse, { id: string }>({
|
||||
query: ({ id }) => `v1/decks/${id}`,
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
|
||||
import { Tab } from '@/services'
|
||||
|
||||
export const decksSlice = createSlice({
|
||||
name: 'decks',
|
||||
initialState: {
|
||||
currentPage: 1,
|
||||
perPage: 10,
|
||||
search: '',
|
||||
authorId: '',
|
||||
minCards: 0,
|
||||
maxCards: null as number | null,
|
||||
maxCards: undefined as number | undefined,
|
||||
currentTab: 'all' as Tab,
|
||||
},
|
||||
reducers: {
|
||||
setCurrentPage: (state, action: PayloadAction<number>) => {
|
||||
@@ -20,8 +22,8 @@ export const decksSlice = createSlice({
|
||||
setSearch: (state, action: PayloadAction<string>) => {
|
||||
state.search = action.payload
|
||||
},
|
||||
setAuthorId: (state, action: PayloadAction<string>) => {
|
||||
state.authorId = action.payload
|
||||
setCurrentTab: (state, action: PayloadAction<Tab>) => {
|
||||
state.currentTab = action.payload
|
||||
},
|
||||
setMinCards: (state, action: PayloadAction<number>) => {
|
||||
state.minCards = action.payload
|
||||
@@ -31,9 +33,9 @@ export const decksSlice = createSlice({
|
||||
},
|
||||
resetFilters: state => {
|
||||
state.search = ''
|
||||
state.authorId = ''
|
||||
state.currentTab = 'all'
|
||||
state.minCards = 0
|
||||
state.maxCards = null
|
||||
state.maxCards = undefined
|
||||
},
|
||||
resetCurrentPage: state => {
|
||||
state.currentPage = 1
|
||||
|
||||
@@ -52,3 +52,15 @@ export type Card = {
|
||||
grade: number
|
||||
userId: string
|
||||
}
|
||||
|
||||
export type GetDecksArgs = {
|
||||
minCardsCount?: number
|
||||
maxCardsCount?: number
|
||||
name?: string
|
||||
authorId?: string
|
||||
orderBy?: string
|
||||
currentPage?: number
|
||||
itemsPerPage?: number
|
||||
}
|
||||
|
||||
export type Tab = 'all' | 'my'
|
||||
|
||||
Reference in New Issue
Block a user