add "show feeds and categories with no unread entries" option

This commit is contained in:
Athou
2022-08-22 13:24:52 +02:00
parent f81491fb32
commit 475c0673a0
5 changed files with 56 additions and 21 deletions

View File

@@ -43,6 +43,11 @@ export const changeScrollSpeed = createAsyncThunk<void, boolean, { state: RootSt
if (!settings) return
client.user.saveSettings({ ...settings, scrollSpeed: speed ? 400 : 0 })
})
export const changeShowRead = createAsyncThunk<void, boolean, { state: RootState }>("settings/showRead", (showRead, thunkApi) => {
const { settings } = thunkApi.getState().user
if (!settings) return
client.user.saveSettings({ ...settings, showRead })
})
export const changeSharingSetting = createAsyncThunk<void, { site: keyof SharingSettings; value: boolean }, { state: RootState }>(
"settings/sharingSetting",
(sharingSetting, thunkApi) => {
@@ -85,16 +90,23 @@ export const userSlice = createSlice({
if (!state.settings) return
state.settings.scrollSpeed = action.meta.arg ? 400 : 0
})
builder.addCase(changeShowRead.pending, (state, action) => {
if (!state.settings) return
state.settings.showRead = action.meta.arg
})
builder.addCase(changeSharingSetting.pending, (state, action) => {
if (!state.settings) return
state.settings.sharingSettings[action.meta.arg.site] = action.meta.arg.value
})
builder.addMatcher(isAnyOf(changeLanguage.fulfilled, changeScrollSpeed.fulfilled, changeSharingSetting.fulfilled), () => {
showNotification({
message: t`Settings saved.`,
color: "green",
})
})
builder.addMatcher(
isAnyOf(changeLanguage.fulfilled, changeScrollSpeed.fulfilled, changeShowRead.fulfilled, changeSharingSetting.fulfilled),
() => {
showNotification({
message: t`Settings saved.`,
color: "green",
})
}
)
},
})

View File

@@ -1,7 +1,7 @@
import { t } from "@lingui/macro"
import { Divider, Select, SimpleGrid, Stack, Switch } from "@mantine/core"
import { Constants } from "app/constants"
import { changeLanguage, changeScrollSpeed, changeSharingSetting } from "app/slices/user"
import { changeLanguage, changeScrollSpeed, changeSharingSetting, changeShowRead } from "app/slices/user"
import { useAppDispatch, useAppSelector } from "app/store"
import { SharingSettings } from "app/types"
import { locales } from "i18n"
@@ -9,6 +9,7 @@ import { locales } from "i18n"
export function DisplaySettings() {
const language = useAppSelector(state => state.user.settings?.language)
const scrollSpeed = useAppSelector(state => state.user.settings?.scrollSpeed)
const showRead = useAppSelector(state => state.user.settings?.showRead)
const sharingSettings = useAppSelector(state => state.user.settings?.sharingSettings)
const dispatch = useAppDispatch()
@@ -30,6 +31,12 @@ export function DisplaySettings() {
onChange={e => dispatch(changeScrollSpeed(e.currentTarget.checked))}
/>
<Switch
label={t`Show feeds and categories with no unread entries`}
checked={showRead}
onChange={e => dispatch(changeShowRead(e.currentTarget.checked))}
/>
<Divider label={t`Sharing sites`} labelPosition="center" />
<SimpleGrid cols={2}>

View File

@@ -22,6 +22,7 @@ const errorThreshold = 9
export function Tree() {
const root = useAppSelector(state => state.tree.rootCategory)
const source = useAppSelector(state => state.entries.source)
const showRead = useAppSelector(state => state.user.settings?.showRead)
const dispatch = useAppDispatch()
const feedClicked = (e: React.MouseEvent, id: string) => {
@@ -74,13 +75,16 @@ export function Tree() {
)
const categoryNode = (category: Category, level: number = 0) => {
const unreadCount = categoryUnreadCount(category)
if (unreadCount === 0 && !showRead) return null
const hasError = !category.expanded && flattenCategoryTree(category).some(c => c.feeds.some(f => f.errorCount > errorThreshold))
return (
<TreeNode
id={category.id}
name={category.name}
icon={category.expanded ? expandedIcon : collapsedIcon}
unread={categoryUnreadCount(category)}
unread={unreadCount}
selected={source.type === "category" && source.id === category.id}
expanded={category.expanded}
level={level}
@@ -92,19 +96,23 @@ export function Tree() {
)
}
const feedNode = (feed: Subscription, level: number = 0) => (
<TreeNode
id={String(feed.id)}
name={feed.name}
icon={feed.iconUrl}
unread={feed.unread}
selected={source.type === "feed" && source.id === String(feed.id)}
level={level}
hasError={feed.errorCount > errorThreshold}
onClick={feedClicked}
key={feed.id}
/>
)
const feedNode = (feed: Subscription, level: number = 0) => {
if (feed.unread === 0 && !showRead) return null
return (
<TreeNode
id={String(feed.id)}
name={feed.name}
icon={feed.iconUrl}
unread={feed.unread}
selected={source.type === "feed" && source.id === String(feed.id)}
level={level}
hasError={feed.errorCount > errorThreshold}
onClick={feedClicked}
key={feed.id}
/>
)
}
const recursiveCategoryNode = (category: Category, level: number = 0) => (
<React.Fragment key={`recursiveCategoryNode-${category.id}`}>

View File

@@ -577,6 +577,10 @@ msgstr "Sharing sites"
msgid "Shift"
msgstr "Shift"
#: src/components/settings/DisplaySettings.tsx
msgid "Show feeds and categories with no unread entries"
msgstr "Show feeds and categories with no unread entries"
#: src/components/KeyboardShortcutsHelp.tsx
msgid "Show keyboard shortcut help"
msgstr "Show keyboard shortcut help"

View File

@@ -577,6 +577,10 @@ msgstr "Sites de partage"
msgid "Shift"
msgstr "Maj"
#: src/components/settings/DisplaySettings.tsx
msgid "Show feeds and categories with no unread entries"
msgstr "Afficher les flux et les catégories pour lesquels tout est déjà lu"
#: src/components/KeyboardShortcutsHelp.tsx
msgid "Show keyboard shortcut help"
msgstr "Montrer les raccourcis clavier"