add support for starring entries

This commit is contained in:
Athou
2022-08-19 10:34:04 +02:00
parent 91bc7fa4b0
commit 973fe56cc8
14 changed files with 104 additions and 19 deletions

View File

@@ -18,6 +18,7 @@ import {
RegistrationRequest,
ServerInfo,
Settings,
StarRequest,
SubscribeRequest,
Subscription,
UserModel,
@@ -44,6 +45,7 @@ export const client = {
},
entry: {
mark: (req: MarkRequest) => axiosInstance.post("entry/mark", req),
star: (req: StarRequest) => axiosInstance.post("entry/star", req),
},
feed: {
get: (id: string) => axiosInstance.get<Subscription>(`feed/get/${id}`),

View File

@@ -1,9 +1,27 @@
import { t } from "@lingui/macro"
import { DEFAULT_THEME } from "@mantine/core"
import { Category } from "./types"
export const Constants = {
categoryIds: {
all: "all",
const categories: { [key: string]: Category } = {
all: {
id: "all",
name: t`All`,
expanded: false,
children: [],
feeds: [],
position: 0,
},
starred: {
id: "starred",
name: t`Starred`,
expanded: false,
children: [],
feeds: [],
position: 1,
},
}
export const Constants = {
categories,
layout: {
mobileBreakpoint: DEFAULT_THEME.breakpoints.md,
headerHeight: 60,

View File

@@ -28,7 +28,7 @@ interface EntriesState {
const initialState: EntriesState = {
source: {
type: "category",
id: Constants.categoryIds.all,
id: Constants.categories.all.id,
},
sourceLabel: "",
sourceWebsiteUrl: "",
@@ -87,6 +87,13 @@ export const markAllEntries = createAsyncThunk<void, { sourceType: EntrySourceTy
thunkApi.dispatch(reloadTree())
}
)
export const starEntry = createAsyncThunk("entries/entry/star", (arg: { entry: Entry; starred: boolean }) => {
client.entry.star({
id: arg.entry.id,
feedId: +arg.entry.feedId,
starred: arg.starred,
})
})
export const selectEntry = createAsyncThunk<void, Entry, { state: RootState }>("entries/entry/select", (arg, thunkApi) => {
const state = thunkApi.getState()
const entry = state.entries.entries.find(e => e.id === arg.id)
@@ -159,6 +166,13 @@ export const entriesSlice = createSlice({
e.read = true
})
})
builder.addCase(starEntry.pending, (state, action) => {
state.entries
.filter(e => action.meta.arg.entry.id === e.id && action.meta.arg.entry.feedId === e.feedId)
.forEach(e => {
e.starred = action.meta.arg.starred
})
})
builder.addCase(loadEntries.pending, (state, action) => {
state.source = action.meta.arg
state.entries = []

View File

@@ -21,7 +21,7 @@ export const redirectToCategory = createAsyncThunk("redirect/category", (id: str
thunkApi.dispatch(redirectTo(`/app/category/${id}`))
)
export const redirectToRootCategory = createAsyncThunk("redirect/category/root", (_, thunkApi) =>
thunkApi.dispatch(redirectToCategory(Constants.categoryIds.all))
thunkApi.dispatch(redirectToCategory(Constants.categories.all.id))
)
export const redirectToCategoryDetails = createAsyncThunk("redirect/category/details", (id: string, thunkApi) =>
thunkApi.dispatch(redirectTo(`/app/category/${id}/details`))