Skip to content

Commit

Permalink
hide source from all articles
Browse files Browse the repository at this point in the history
  • Loading branch information
yang991178 committed Jun 19, 2022
1 parent 59cc729 commit b0aa102
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 9 deletions.
2 changes: 1 addition & 1 deletion electron-builder-mas.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: DevHYLiu.FluentReader
buildVersion: 26
buildVersion: 27
productName: Fluent Reader
copyright: Copyright © 2020 Haoyuan Liu
files:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fluent-reader",
"version": "1.1.1",
"version": "1.1.2",
"description": "Modern desktop RSS reader",
"main": "./dist/electron.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/components/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class Menu extends React.Component<MenuProps> {
intl.get("allArticles") +
this.countOverflow(
Object.values(this.props.sources)
.filter(s => !s.hidden)
.map(s => s.unreadCount)
.reduce((a, b) => a + b, 0)
),
Expand Down
23 changes: 23 additions & 0 deletions src/components/settings/sources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Dropdown,
MessageBar,
MessageBarType,
Toggle,
} from "@fluentui/react"
import {
SourceState,
Expand All @@ -42,6 +43,7 @@ type SourcesTabProps = {
deleteSources: (sources: RSSSource[]) => void
importOPML: () => void
exportOPML: () => void
toggleSourceHidden: (source: RSSSource) => void
}

type SourcesTabState = {
Expand Down Expand Up @@ -217,6 +219,16 @@ class SourcesTab extends React.Component<SourcesTabProps, SourcesTabState> {
})
}

onToggleHidden = () => {
this.props.toggleSourceHidden(this.state.selectedSource)
this.setState({
selectedSource: {
...this.state.selectedSource,
hidden: !this.state.selectedSource.hidden,
} as RSSSource,
})
}

render = () => (
<div className="tab-body">
{this.props.serviceOn && (
Expand Down Expand Up @@ -409,6 +421,17 @@ class SourcesTab extends React.Component<SourcesTabProps, SourcesTabState> {
)}
onChange={this.onOpenTargetChange}
/>
<Stack horizontal verticalAlign="baseline">
<Stack.Item grow>
<Label>{intl.get("sources.hidden")}</Label>
</Stack.Item>
<Stack.Item>
<Toggle
checked={this.state.selectedSource.hidden}
onChange={this.onToggleHidden}
/>
</Stack.Item>
</Stack>
{!this.state.selectedSource.serviceRef && (
<Stack horizontal>
<Stack.Item>
Expand Down
3 changes: 3 additions & 0 deletions src/containers/settings/sources-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
deleteSource,
SourceOpenTarget,
deleteSources,
toggleSourceHidden,
} from "../../scripts/models/source"
import { importOPML, exportOPML } from "../../scripts/models/group"
import { AppDispatch, validateFavicon } from "../../scripts/utils"
Expand Down Expand Up @@ -67,6 +68,8 @@ const mapDispatchToProps = (dispatch: AppDispatch) => {
dispatch(deleteSources(sources)),
importOPML: () => dispatch(importOPML()),
exportOPML: () => dispatch(exportOPML()),
toggleSourceHidden: (source: RSSSource) =>
dispatch(toggleSourceHidden(source)),
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/scripts/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import lf from "lovefield"
import { RSSSource } from "./models/source"
import { RSSItem } from "./models/item"

const sdbSchema = lf.schema.create("sourcesDB", 2)
const sdbSchema = lf.schema.create("sourcesDB", 3)
sdbSchema
.createTable("sources")
.addColumn("sid", lf.Type.INTEGER)
Expand All @@ -18,6 +18,7 @@ sdbSchema
.addColumn("fetchFrequency", lf.Type.NUMBER)
.addColumn("rules", lf.Type.OBJECT)
.addColumn("textDir", lf.Type.NUMBER)
.addColumn("hidden", lf.Type.BOOLEAN)
.addNullable(["iconurl", "serviceRef", "rules"])
.addIndex("idxURL", ["url"], true)

Expand Down Expand Up @@ -54,6 +55,9 @@ async function onUpgradeSourceDB(rawDb: lf.raw.BackStore) {
if (version < 2) {
await rawDb.addTableColumn("sources", "textDir", 0)
}
if (version < 3) {
await rawDb.addTableColumn("sources", "hidden", false)
}
}

export async function init() {
Expand Down Expand Up @@ -99,6 +103,7 @@ async function migrateNeDB() {
delete doc._id
if (!doc.fetchFrequency) doc.fetchFrequency = 0
doc.textDir = 0
doc.hidden = false
return sources.createRow(doc)
})
const iRows = itemDocs.map(doc => {
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@
"badUrl": "Invalid URL",
"deleteWarning": "The source and all saved articles will be removed.",
"selected": "Selected source",
"selectedMulti": "Selected multiple sources"
"selectedMulti": "Selected multiple sources",
"hidden": "Hide in \"all articles\""
},
"groups": {
"exist": "This group already exists.",
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
"badUrl": "请正确输入URL",
"deleteWarning": "这将移除订阅源与所有已保存的文章",
"selected": "选中订阅源",
"selectedMulti": "选中多个订阅源"
"selectedMulti": "选中多个订阅源",
"hidden": "从“全部文章”中隐藏"
},
"groups": {
"exist": "该分组已存在",
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
"badUrl": "請正確輸入URL",
"deleteWarning": "這將移除訂閱源與所有已儲存的文章",
"selected": "選中訂閱源",
"selectedMulti": "選中多個訂閱源"
"selectedMulti": "選中多個訂閱源",
"hidden": "從“全部文章”中隱藏"
},
"groups": {
"exist": "該分組已存在",
Expand Down
10 changes: 8 additions & 2 deletions src/scripts/models/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
INIT_SOURCES,
ADD_SOURCE,
DELETE_SOURCE,
UNHIDE_SOURCE,
HIDE_SOURCE,
} from "./source"
import {
ItemActionTypes,
Expand Down Expand Up @@ -316,13 +318,16 @@ export function feedReducer(
...state,
[ALL]: new RSSFeed(
ALL,
Object.values(action.sources).map(s => s.sid)
Object.values(action.sources)
.filter(s => !s.hidden)
.map(s => s.sid)
),
}
default:
return state
}
case ADD_SOURCE:
case UNHIDE_SOURCE:
switch (action.status) {
case ActionStatus.Success:
return {
Expand All @@ -336,7 +341,8 @@ export function feedReducer(
default:
return state
}
case DELETE_SOURCE: {
case DELETE_SOURCE:
case HIDE_SOURCE: {
let nextState = {}
for (let [id, feed] of Object.entries(state)) {
nextState[id] = new RSSFeed(
Expand Down
24 changes: 24 additions & 0 deletions src/scripts/models/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class RSSSource {
fetchFrequency: number // in minutes
rules?: SourceRule[]
textDir: SourceTextDirection
hidden: boolean

constructor(url: string, name: string = null) {
this.url = url
Expand All @@ -49,6 +50,7 @@ export class RSSSource {
this.lastFetched = new Date()
this.fetchFrequency = 0
this.textDir = SourceTextDirection.LTR
this.hidden = false
}

static async fetchMetaData(source: RSSSource) {
Expand Down Expand Up @@ -120,6 +122,8 @@ export const ADD_SOURCE = "ADD_SOURCE"
export const UPDATE_SOURCE = "UPDATE_SOURCE"
export const UPDATE_UNREAD_COUNTS = "UPDATE_UNREAD_COUNTS"
export const DELETE_SOURCE = "DELETE_SOURCE"
export const HIDE_SOURCE = "HIDE_SOURCE"
export const UNHIDE_SOURCE = "UNHIDE_SOURCE"

interface InitSourcesAction {
type: typeof INIT_SOURCES
Expand Down Expand Up @@ -151,12 +155,19 @@ interface DeleteSourceAction {
source: RSSSource
}

interface ToggleSourceHiddenAction {
type: typeof HIDE_SOURCE | typeof UNHIDE_SOURCE
status: ActionStatus
source: RSSSource
}

export type SourceActionTypes =
| InitSourcesAction
| AddSourceAction
| UpdateSourceAction
| UpdateUnreadCountsAction
| DeleteSourceAction
| ToggleSourceHiddenAction

export function initSourcesRequest(): SourceActionTypes {
return {
Expand Down Expand Up @@ -382,6 +393,19 @@ export function deleteSources(sources: RSSSource[]): AppThunk<Promise<void>> {
}
}

export function toggleSourceHidden(source: RSSSource): AppThunk<Promise<void>> {
return async (dispatch, getState) => {
const sourceCopy: RSSSource = { ...getState().sources[source.sid] }
sourceCopy.hidden = !sourceCopy.hidden
dispatch({
type: sourceCopy.hidden ? HIDE_SOURCE : UNHIDE_SOURCE,
status: ActionStatus.Success,
source: sourceCopy,
})
await dispatch(updateSource(sourceCopy))
}
}

export function updateFavicon(
sids?: number[],
force = false
Expand Down

0 comments on commit b0aa102

Please sign in to comment.