mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-26 12:33:39 +00:00
chore: lint with tabwidth: 2
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
export const baseApi = createApi({
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: 'https://api.flashcards.andrii.es',
|
||||
credentials: 'include',
|
||||
prepareHeaders: headers => {
|
||||
headers.append('x-auth-skip', 'true')
|
||||
},
|
||||
}),
|
||||
endpoints: () => ({}),
|
||||
reducerPath: 'baseApi',
|
||||
tagTypes: ['Decks'],
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: 'https://api.flashcards.andrii.es',
|
||||
credentials: 'include',
|
||||
prepareHeaders: headers => {
|
||||
headers.append('x-auth-skip', 'true')
|
||||
},
|
||||
}),
|
||||
endpoints: () => ({}),
|
||||
reducerPath: 'baseApi',
|
||||
tagTypes: ['Decks'],
|
||||
})
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
import {
|
||||
CardsResponse,
|
||||
CreateDeckArgs,
|
||||
DeckResponse,
|
||||
DecksResponse,
|
||||
GetDecksArgs,
|
||||
UpdateDeckArgs,
|
||||
CardsResponse,
|
||||
CreateDeckArgs,
|
||||
DeckResponse,
|
||||
DecksResponse,
|
||||
GetDecksArgs,
|
||||
UpdateDeckArgs,
|
||||
} from './decks.types'
|
||||
import { baseApi } from '@/services'
|
||||
|
||||
const decksService = baseApi.injectEndpoints({
|
||||
endpoints: builder => ({
|
||||
createDeck: builder.mutation<DeckResponse, CreateDeckArgs>({
|
||||
invalidatesTags: ['Decks'],
|
||||
onQueryStarted: async (_, { dispatch, getCacheEntry, getState, queryFulfilled }) => {
|
||||
const data = getCacheEntry()
|
||||
const state = getState()
|
||||
endpoints: builder => ({
|
||||
createDeck: builder.mutation<DeckResponse, CreateDeckArgs>({
|
||||
invalidatesTags: ['Decks'],
|
||||
onQueryStarted: async (_, { dispatch, getCacheEntry, getState, queryFulfilled }) => {
|
||||
const data = getCacheEntry()
|
||||
const state = getState()
|
||||
|
||||
decksService.util.re
|
||||
await queryFulfilled
|
||||
},
|
||||
query: body => ({
|
||||
body,
|
||||
method: 'POST',
|
||||
url: `v1/decks`,
|
||||
}),
|
||||
}),
|
||||
deleteDeck: builder.mutation<void, { id: string }>({
|
||||
invalidatesTags: ['Decks'],
|
||||
query: ({ id }) => ({
|
||||
method: 'DELETE',
|
||||
url: `v1/decks/${id}`,
|
||||
}),
|
||||
}),
|
||||
getDeckById: builder.query<DeckResponse, { id: string }>({
|
||||
query: ({ id }) => `v1/decks/${id}`,
|
||||
}),
|
||||
getDeckCards: builder.query<CardsResponse, { id: string }>({
|
||||
query: ({ id }) => `v1/decks/${id}/cards`,
|
||||
}),
|
||||
getDecks: builder.query<DecksResponse, GetDecksArgs | void>({
|
||||
providesTags: ['Decks'],
|
||||
query: args => {
|
||||
return {
|
||||
params: args ?? undefined,
|
||||
url: `v1/decks`,
|
||||
}
|
||||
},
|
||||
}),
|
||||
updateDeck: builder.mutation<DeckResponse, UpdateDeckArgs>({
|
||||
invalidatesTags: ['Decks'],
|
||||
query: ({ id, ...body }) => ({
|
||||
body,
|
||||
method: 'PATCH',
|
||||
url: `v1/decks/${id}`,
|
||||
}),
|
||||
}),
|
||||
decksService.util.re
|
||||
await queryFulfilled
|
||||
},
|
||||
query: body => ({
|
||||
body,
|
||||
method: 'POST',
|
||||
url: `v1/decks`,
|
||||
}),
|
||||
}),
|
||||
deleteDeck: builder.mutation<void, { id: string }>({
|
||||
invalidatesTags: ['Decks'],
|
||||
query: ({ id }) => ({
|
||||
method: 'DELETE',
|
||||
url: `v1/decks/${id}`,
|
||||
}),
|
||||
}),
|
||||
getDeckById: builder.query<DeckResponse, { id: string }>({
|
||||
query: ({ id }) => `v1/decks/${id}`,
|
||||
}),
|
||||
getDeckCards: builder.query<CardsResponse, { id: string }>({
|
||||
query: ({ id }) => `v1/decks/${id}/cards`,
|
||||
}),
|
||||
getDecks: builder.query<DecksResponse, GetDecksArgs | void>({
|
||||
providesTags: ['Decks'],
|
||||
query: args => {
|
||||
return {
|
||||
params: args ?? undefined,
|
||||
url: `v1/decks`,
|
||||
}
|
||||
},
|
||||
}),
|
||||
updateDeck: builder.mutation<DeckResponse, UpdateDeckArgs>({
|
||||
invalidatesTags: ['Decks'],
|
||||
query: ({ id, ...body }) => ({
|
||||
body,
|
||||
method: 'PATCH',
|
||||
url: `v1/decks/${id}`,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
export const {
|
||||
useCreateDeckMutation,
|
||||
useDeleteDeckMutation,
|
||||
useGetDeckByIdQuery,
|
||||
useGetDeckCardsQuery,
|
||||
useGetDecksQuery,
|
||||
useUpdateDeckMutation,
|
||||
useCreateDeckMutation,
|
||||
useDeleteDeckMutation,
|
||||
useGetDeckByIdQuery,
|
||||
useGetDeckCardsQuery,
|
||||
useGetDecksQuery,
|
||||
useUpdateDeckMutation,
|
||||
} = decksService
|
||||
|
||||
@@ -2,42 +2,42 @@ import { Tab } from '@/services'
|
||||
import { PayloadAction, createSlice } from '@reduxjs/toolkit'
|
||||
|
||||
export const decksSlice = createSlice({
|
||||
initialState: {
|
||||
currentPage: 1,
|
||||
currentTab: 'all' as Tab,
|
||||
maxCards: undefined as number | undefined,
|
||||
minCards: 0,
|
||||
perPage: 10,
|
||||
search: '',
|
||||
initialState: {
|
||||
currentPage: 1,
|
||||
currentTab: 'all' as Tab,
|
||||
maxCards: undefined as number | undefined,
|
||||
minCards: 0,
|
||||
perPage: 10,
|
||||
search: '',
|
||||
},
|
||||
name: 'decks',
|
||||
reducers: {
|
||||
resetCurrentPage: state => {
|
||||
state.currentPage = 1
|
||||
},
|
||||
name: 'decks',
|
||||
reducers: {
|
||||
resetCurrentPage: state => {
|
||||
state.currentPage = 1
|
||||
},
|
||||
resetFilters: state => {
|
||||
state.search = ''
|
||||
state.currentTab = 'all'
|
||||
state.minCards = 0
|
||||
state.maxCards = undefined
|
||||
},
|
||||
setCurrentPage: (state, action: PayloadAction<number>) => {
|
||||
state.currentPage = action.payload
|
||||
},
|
||||
setCurrentTab: (state, action: PayloadAction<Tab>) => {
|
||||
state.currentTab = action.payload
|
||||
},
|
||||
setMaxCards: (state, action: PayloadAction<number>) => {
|
||||
state.maxCards = action.payload
|
||||
},
|
||||
setMinCards: (state, action: PayloadAction<number>) => {
|
||||
state.minCards = action.payload
|
||||
},
|
||||
setPerPage: (state, action: PayloadAction<number>) => {
|
||||
state.perPage = action.payload
|
||||
},
|
||||
setSearch: (state, action: PayloadAction<string>) => {
|
||||
state.search = action.payload
|
||||
},
|
||||
resetFilters: state => {
|
||||
state.search = ''
|
||||
state.currentTab = 'all'
|
||||
state.minCards = 0
|
||||
state.maxCards = undefined
|
||||
},
|
||||
setCurrentPage: (state, action: PayloadAction<number>) => {
|
||||
state.currentPage = action.payload
|
||||
},
|
||||
setCurrentTab: (state, action: PayloadAction<Tab>) => {
|
||||
state.currentTab = action.payload
|
||||
},
|
||||
setMaxCards: (state, action: PayloadAction<number>) => {
|
||||
state.maxCards = action.payload
|
||||
},
|
||||
setMinCards: (state, action: PayloadAction<number>) => {
|
||||
state.minCards = action.payload
|
||||
},
|
||||
setPerPage: (state, action: PayloadAction<number>) => {
|
||||
state.perPage = action.payload
|
||||
},
|
||||
setSearch: (state, action: PayloadAction<string>) => {
|
||||
state.search = action.payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
export type Pagination = {
|
||||
currentPage: number
|
||||
itemsPerPage: number
|
||||
totalItems: number
|
||||
totalPages: number
|
||||
currentPage: number
|
||||
itemsPerPage: number
|
||||
totalItems: number
|
||||
totalPages: number
|
||||
}
|
||||
|
||||
export type Author = {
|
||||
id: string
|
||||
name: string
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export type Deck = {
|
||||
author: Author
|
||||
cardsCount: number
|
||||
cover?: null | string
|
||||
created: string
|
||||
id: string
|
||||
isBlocked?: boolean | null
|
||||
isDeleted: boolean | null
|
||||
isPrivate: boolean
|
||||
name: string
|
||||
rating: number
|
||||
shots: number
|
||||
updated: string
|
||||
userId: string
|
||||
author: Author
|
||||
cardsCount: number
|
||||
cover?: null | string
|
||||
created: string
|
||||
id: string
|
||||
isBlocked?: boolean | null
|
||||
isDeleted: boolean | null
|
||||
isPrivate: boolean
|
||||
name: string
|
||||
rating: number
|
||||
shots: number
|
||||
updated: string
|
||||
userId: string
|
||||
}
|
||||
|
||||
export type DecksResponse = {
|
||||
items: Deck[]
|
||||
maxCardsCount: number
|
||||
pagination: Pagination
|
||||
items: Deck[]
|
||||
maxCardsCount: number
|
||||
pagination: Pagination
|
||||
}
|
||||
|
||||
export type DeckResponse = Deck
|
||||
|
||||
export type CardsResponse = {
|
||||
items: Card[]
|
||||
pagination: Pagination
|
||||
items: Card[]
|
||||
pagination: Pagination
|
||||
}
|
||||
|
||||
export type Card = {
|
||||
answer: string
|
||||
answerImg?: null | string
|
||||
created: string
|
||||
deckId: string
|
||||
grade: number
|
||||
id: string
|
||||
question: string
|
||||
questionImg?: null | string
|
||||
shots: number
|
||||
updated: string
|
||||
userId: string
|
||||
answer: string
|
||||
answerImg?: null | string
|
||||
created: string
|
||||
deckId: string
|
||||
grade: number
|
||||
id: string
|
||||
question: string
|
||||
questionImg?: null | string
|
||||
shots: number
|
||||
updated: string
|
||||
userId: string
|
||||
}
|
||||
|
||||
export type GetDecksArgs = {
|
||||
authorId?: string
|
||||
currentPage?: number
|
||||
itemsPerPage?: number
|
||||
maxCardsCount?: number
|
||||
minCardsCount?: number
|
||||
name?: string
|
||||
orderBy?: string
|
||||
authorId?: string
|
||||
currentPage?: number
|
||||
itemsPerPage?: number
|
||||
maxCardsCount?: number
|
||||
minCardsCount?: number
|
||||
name?: string
|
||||
orderBy?: string
|
||||
}
|
||||
|
||||
export type CreateDeckArgs = {
|
||||
cover?: string
|
||||
isPrivate?: boolean
|
||||
name: string
|
||||
cover?: string
|
||||
isPrivate?: boolean
|
||||
name: string
|
||||
}
|
||||
|
||||
export type UpdateDeckArgs = Partial<CreateDeckArgs> & { id: Deck['id'] }
|
||||
|
||||
@@ -6,11 +6,11 @@ import { configureStore } from '@reduxjs/toolkit'
|
||||
import { setupListeners } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
export const store = configureStore({
|
||||
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(baseApi.middleware),
|
||||
reducer: {
|
||||
[baseApi.reducerPath]: baseApi.reducer,
|
||||
[decksSlice.name]: decksSlice.reducer,
|
||||
},
|
||||
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(baseApi.middleware),
|
||||
reducer: {
|
||||
[baseApi.reducerPath]: baseApi.reducer,
|
||||
[decksSlice.name]: decksSlice.reducer,
|
||||
},
|
||||
})
|
||||
|
||||
export type AppDispatch = typeof store.dispatch
|
||||
|
||||
Reference in New Issue
Block a user