Skip to content

Commit 0a9c5f2

Browse files
committed
! Fix incorrect code, use #reduce instead
1 parent 7f1bf1d commit 0a9c5f2

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/renderer/views/Channel/Channel.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,21 +2048,20 @@ async function searchChannelLocal() {
20482048
contents = result.contents.contents
20492049
}
20502050
2051-
const results = []
2052-
contents
2051+
const results = contents
20532052
.filter(node => node.type === 'ItemSection')
20542053
.flatMap(itemSection => itemSection.contents)
2055-
.forEach(item => {
2054+
.reduce((items, item) => {
20562055
if (item.type === 'Video') {
20572056
const video = parseLocalListVideo(item)
20582057
if (video.isMemberOnly || video.isMemberFirst) { return null }
20592058
2060-
results.push(video)
2059+
items.push(video)
20612060
} else if (!hideChannelPlaylists.value && item.type === 'Playlist') {
2062-
results.push(parseLocalListPlaylist(item, id.value, channelName.value))
2061+
items.push(parseLocalListPlaylist(item, id.value, channelName.value))
20632062
}
2064-
})
2065-
.filter(item => item != null)
2063+
return items
2064+
}, [])
20662065
20672066
if (isNewSearch) {
20682067
searchResults.value = results

src/renderer/views/Hashtag/Hashtag.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,13 @@ async function getInvidiousHashtag(page = 1) {
148148
async function getLocalHashtag() {
149149
try {
150150
const hashtagData = await getHashtagLocal(hashtag.value)
151-
videos.value = hashtagData.videos.map((video) => parseLocalListVideo(video))
152-
.filter(v => !v.isMemberOnly && !v.isMemberFirst)
151+
videos.value = hashtagData.videos.reduce((results, video) => {
152+
const v = parseLocalListVideo(video)
153+
if (v.isMemberOnly || v.isMemberFirst) {
154+
results.push(v)
155+
}
156+
return results
157+
}, [])
153158
apiUsed.value = 'local'
154159
hashtagContinuationData.value = hashtagData.has_continuation ? hashtagData : null
155160
isLoading.value = false
@@ -172,8 +177,13 @@ async function getLocalHashtag() {
172177
async function getLocalHashtagMore() {
173178
try {
174179
const continuation = await hashtagContinuationData.value.getContinuation()
175-
const newVideos = continuation.videos.map((video) => parseLocalListVideo(video))
176-
.filter(v => !v.isMemberOnly && !v.isMemberFirst)
180+
const newVideos = continuation.videos.reduce((results, video) => {
181+
const v = parseLocalListVideo(video)
182+
if (v.isMemberOnly || v.isMemberFirst) {
183+
results.push(v)
184+
}
185+
return results
186+
}, [])
177187
hashtagContinuationData.value = continuation.has_continuation ? continuation : null
178188
videos.value = videos.value.concat(newVideos)
179189
} catch (error) {

0 commit comments

Comments
 (0)