Skip to content

Commit

Permalink
fix: hide folder/feeds with no unread items when showAll is disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Wolfgang <github@linux-dude.de>
  • Loading branch information
wofferl committed Oct 20, 2024
1 parent 578b7ec commit 76e30f2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the

### Fixed
- 25.0.0-alpha2: Feed folderbar menu always opens collapsed (#2508)

Check failure on line 12 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'folderbar'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'folderbar'?", "location": {"path": "CHANGELOG.md", "range": {"start": {"line": 12, "column": 23}}}, "severity": "ERROR"}
- fix: hide folder/feeds with no unread items when showAll is disabled (#2503)

Check failure on line 13 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'showAll'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'showAll'?", "location": {"path": "CHANGELOG.md", "range": {"start": {"line": 13, "column": 52}}}, "severity": "ERROR"}


# Releases
Expand Down
54 changes: 32 additions & 22 deletions src/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ import FolderPlusIcon from 'vue-material-design-icons/FolderPlus.vue'
import PlusIcon from 'vue-material-design-icons/Plus.vue'
import { ROUTES } from '../routes'
import { ACTIONS, AppState } from '../store'
import { ACTIONS } from '../store'
import AddFeed from './AddFeed.vue'
import SidebarFeedLinkActions from './SidebarFeedLinkActions.vue'
Expand All @@ -195,26 +195,6 @@ import HelpModal from './modals/HelpModal.vue'
import { Folder } from '../types/Folder'
import { Feed } from '../types/Feed'
const SideBarState = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
topLevelNav(localState: any, state: AppState): (Feed | Folder)[] {
let navItems: (Feed | Folder)[] = state.feeds.filter((feed: Feed) => {
return feed.folderId === undefined || feed.folderId === null
})
navItems = navItems.concat(state.folders)
// bring pinned items to the top
return navItems.sort((item, item2) => {
if ((item as Feed).pinned && !(item2 as Feed).pinned) {
return -1
} else if ((item2 as Feed).pinned && !(item as Feed).pinned) {
return 1
}
return 0
})
},
}
export default Vue.extend({
components: {
NcAppNavigation,
Expand Down Expand Up @@ -244,7 +224,37 @@ export default Vue.extend({
},
computed: {
...mapState(['feeds', 'folders', 'items']),
...mapState(SideBarState),
topLevelNav(): (Feed | Folder)[] {
const showAll = this.$store.getters.showAll
const feeds: { pinned: Feed[], visible: Feed[], ungrouped: Feed[] } = this.$store.getters.feeds.reduce((result, feed: Feed) => {
if (feed.pinned) result.pinned.push(feed)
if (showAll || feed.unreadCount > 0) {
result.visible.push(feed)
if (feed.folderId === undefined || feed.folderId === null) {
result.ungrouped.push(feed)
}
}
return result
}, { pinned: [], visible: [], ungrouped: [] })
const visibleFolders = this.$store.getters.folders
.filter((folder: Folder) => {
return showAll || feeds.visible.some((feed: Feed) => feed.folderId === folder.id)
})
.map((folder: Folder) => {
folder.feeds = feeds.visible.filter((feed: Feed) => feed.folderId === folder.id)
return folder
})
const navItems: (Feed | Folder)[] = [
...feeds.pinned,
...feeds.ungrouped,
...visibleFolders,
]
return navItems
},
loading: {
get() {
return this.$store.getters.loading
Expand Down
7 changes: 7 additions & 0 deletions tests/javascript/unit/components/Sidebar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Sidebar.vue', () => {
},
getters: {
feeds,
showAll: () => { return true },
},
dispatch: jest.fn(),
},
Expand Down Expand Up @@ -97,6 +98,7 @@ describe('Sidebar.vue', () => {
getters: {
feeds: [],
folders: [],
showAll: () => { return true },
},
},
})
Expand All @@ -112,6 +114,7 @@ describe('Sidebar.vue', () => {
getters: {
feeds,
folders,
showAll: () => { return true },
},
},
})
Expand All @@ -127,6 +130,7 @@ describe('Sidebar.vue', () => {
getters: {
feeds,
folders,
showAll: () => { return true },
},
},
})
Expand All @@ -142,6 +146,7 @@ describe('Sidebar.vue', () => {
getters: {
feeds,
folders,
showAll: () => { return true },
},
},
})
Expand All @@ -157,6 +162,7 @@ describe('Sidebar.vue', () => {
getters: {
feeds,
folders,
showAll: () => { return true },
},
},
})
Expand All @@ -172,6 +178,7 @@ describe('Sidebar.vue', () => {
getters: {
feeds,
folders,
showAll: () => { return true },
},
},
})
Expand Down

0 comments on commit 76e30f2

Please sign in to comment.