createAppAsyncThunk needs to be in its own file (https://stackoverflow.com/a/77136003/1885506)

This commit is contained in:
Athou
2023-12-28 21:45:17 +01:00
parent 97781d5551
commit bb4bb0c7d7
7 changed files with 23 additions and 12 deletions

View File

@@ -1,7 +1,8 @@
import { createSlice, type PayloadAction } from "@reduxjs/toolkit"
import { client } from "app/client"
import { Constants } from "app/constants"
import { createAppAsyncThunk, type RootState } from "app/store"
import { type RootState } from "app/store"
import { createAppAsyncThunk } from "app/thunk"
import { type Entry, type MarkRequest, type TagRequest } from "app/types"
import { scrollToWithCallback } from "app/utils"
import { flushSync } from "react-dom"
@@ -11,10 +12,12 @@ import { reloadTree } from "./tree"
import { reloadTags } from "./user"
export type EntrySourceType = "category" | "feed" | "tag"
export interface EntrySource {
type: EntrySourceType
id: string
}
export type ExpendableEntry = Entry & { expanded?: boolean }
interface EntriesState {
@@ -188,7 +191,12 @@ export const selectEntry = createAppAsyncThunk(
// expand if requested
const previouslySelectedEntry = state.entries.entries.find(e => e.id === state.entries.selectedEntryId)
if (previouslySelectedEntry) {
thunkApi.dispatch(entriesSlice.actions.setEntryExpanded({ entry: previouslySelectedEntry, expanded: false }))
thunkApi.dispatch(
entriesSlice.actions.setEntryExpanded({
entry: previouslySelectedEntry,
expanded: false,
})
)
}
thunkApi.dispatch(entriesSlice.actions.setEntryExpanded({ entry, expanded: arg.expand }))
})

View File

@@ -1,6 +1,6 @@
import { createSlice, type PayloadAction } from "@reduxjs/toolkit"
import { Constants } from "app/constants"
import { createAppAsyncThunk } from "app/store"
import { createAppAsyncThunk } from "app/thunk"
interface RedirectState {
to?: string

View File

@@ -1,6 +1,6 @@
import { type PayloadAction, createSlice } from "@reduxjs/toolkit"
import { createSlice, type PayloadAction } from "@reduxjs/toolkit"
import { client } from "app/client"
import { createAppAsyncThunk } from "app/store"
import { createAppAsyncThunk } from "app/thunk"
import { type ServerInfo } from "app/types"
interface ServerState {

View File

@@ -1,6 +1,6 @@
import { createSlice, type PayloadAction } from "@reduxjs/toolkit"
import { client } from "app/client"
import { createAppAsyncThunk } from "app/store"
import { createAppAsyncThunk } from "app/thunk"
import { type Category, type CollapseRequest } from "app/types"
import { visitCategoryTree } from "app/utils"
// eslint-disable-next-line import/no-cycle

View File

@@ -2,7 +2,7 @@ import { t } from "@lingui/macro"
import { showNotification } from "@mantine/notifications"
import { createSlice, isAnyOf } from "@reduxjs/toolkit"
import { client } from "app/client"
import { createAppAsyncThunk } from "app/store"
import { createAppAsyncThunk } from "app/thunk"
import { type ReadingMode, type ReadingOrder, type Settings, type SharingSettings, type UserModel } from "app/types"
// eslint-disable-next-line import/no-cycle
import { reloadEntries } from "./entries"

View File

@@ -1,4 +1,4 @@
import { configureStore, createAsyncThunk } from "@reduxjs/toolkit"
import { configureStore } from "@reduxjs/toolkit"
import { setupListeners } from "@reduxjs/toolkit/query"
import { type TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"
import entriesReducer from "./slices/entries"
@@ -24,7 +24,3 @@ export type AppDispatch = typeof store.dispatch
export const useAppDispatch: () => AppDispatch = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
export const createAppAsyncThunk = createAsyncThunk.withTypes<{
state: RootState
dispatch: AppDispatch
}>()

View File

@@ -0,0 +1,7 @@
import { createAsyncThunk } from "@reduxjs/toolkit"
import { type AppDispatch, type RootState } from "app/store"
export const createAppAsyncThunk = createAsyncThunk.withTypes<{
state: RootState
dispatch: AppDispatch
}>()