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

View File

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

View File

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

View File

@@ -577,6 +577,10 @@ msgstr "Sharing sites"
msgid "Shift" msgid "Shift"
msgstr "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 #: src/components/KeyboardShortcutsHelp.tsx
msgid "Show keyboard shortcut help" msgid "Show keyboard shortcut help"
msgstr "Show keyboard shortcut help" msgstr "Show keyboard shortcut help"

View File

@@ -577,6 +577,10 @@ msgstr "Sites de partage"
msgid "Shift" msgid "Shift"
msgstr "Maj" 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 #: src/components/KeyboardShortcutsHelp.tsx
msgid "Show keyboard shortcut help" msgid "Show keyboard shortcut help"
msgstr "Montrer les raccourcis clavier" msgstr "Montrer les raccourcis clavier"