style: 🧑💻 update types ont loop functions
This commit is contained in:
parent
75b9e05999
commit
6cd1058048
@ -2,7 +2,7 @@
|
|||||||
<NcAppNavigationList class="list">
|
<NcAppNavigationList class="list">
|
||||||
<NcAppNavigationNewItem
|
<NcAppNavigationNewItem
|
||||||
:name="t('repod', 'Add a RSS link')"
|
:name="t('repod', 'Add a RSS link')"
|
||||||
@new-item="(url) => $router.push(toFeedUrl(url))">
|
@new-item="(url: string) => $router.push(toFeedUrl(url))">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<PlusIcon :size="20" />
|
<PlusIcon :size="20" />
|
||||||
</template>
|
</template>
|
||||||
|
@ -110,7 +110,8 @@ export default {
|
|||||||
)
|
)
|
||||||
if (currentSearch === this.value) {
|
if (currentSearch === this.value) {
|
||||||
this.feeds = [...feeds.data].sort(
|
this.feeds = [...feeds.data].sort(
|
||||||
(a, b) => b.fetchedAtUnix - a.fetchedAtUnix,
|
(a: PodcastDataInterface, b: PodcastDataInterface) =>
|
||||||
|
b.fetchedAtUnix - a.fetchedAtUnix,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<Loading v-if="loading" />
|
<Loading v-if="loading" />
|
||||||
<ul v-if="!loading">
|
<ul v-if="!loading">
|
||||||
<NcListItem
|
<NcListItem
|
||||||
v-if="!episodes.every((e) => !e.selected)"
|
v-if="!episodes.every((e: EpisodeInterface) => !e.selected)"
|
||||||
:active="true"
|
:active="true"
|
||||||
:force-display-actions="true"
|
:force-display-actions="true"
|
||||||
:name="
|
:name="
|
||||||
@ -11,7 +11,7 @@
|
|||||||
'repod',
|
'repod',
|
||||||
'%n episode selected',
|
'%n episode selected',
|
||||||
'%n episodes selected',
|
'%n episodes selected',
|
||||||
episodes.filter((e) => e.selected).length,
|
episodes.filter((e: EpisodeInterface) => e.selected).length,
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
:one-line="true">
|
:one-line="true">
|
||||||
@ -19,14 +19,14 @@
|
|||||||
<NcActionButton
|
<NcActionButton
|
||||||
v-if="
|
v-if="
|
||||||
episodes
|
episodes
|
||||||
.filter((e) => e.selected)
|
.filter((e: EpisodeInterface) => e.selected)
|
||||||
.filter((e) => !hasEnded(e)).length
|
.filter((e: EpisodeInterface) => !hasEnded(e)).length
|
||||||
"
|
"
|
||||||
:aria-label="t('repod', 'Read all')"
|
:aria-label="t('repod', 'Read all')"
|
||||||
:disabled="
|
:disabled="
|
||||||
!episodes
|
!episodes
|
||||||
.filter((e) => e.selected)
|
.filter((e: EpisodeInterface) => e.selected)
|
||||||
.every((e) => e.duration)
|
.every((e: EpisodeInterface) => e.duration)
|
||||||
"
|
"
|
||||||
:name="t('repod', 'Read all')"
|
:name="t('repod', 'Read all')"
|
||||||
:title="t('repod', 'Read all')"
|
:title="t('repod', 'Read all')"
|
||||||
@ -38,14 +38,14 @@
|
|||||||
<NcActionButton
|
<NcActionButton
|
||||||
v-if="
|
v-if="
|
||||||
episodes
|
episodes
|
||||||
.filter((e) => e.selected)
|
.filter((e: EpisodeInterface) => e.selected)
|
||||||
.every((e) => hasEnded(e))
|
.every((e: EpisodeInterface) => hasEnded(e))
|
||||||
"
|
"
|
||||||
:aria-label="t('repod', 'Unread all')"
|
:aria-label="t('repod', 'Unread all')"
|
||||||
:disabled="
|
:disabled="
|
||||||
!episodes
|
!episodes
|
||||||
.filter((e) => e.selected)
|
.filter((e: EpisodeInterface) => e.selected)
|
||||||
.every((e) => e.duration)
|
.every((e: EpisodeInterface) => e.duration)
|
||||||
"
|
"
|
||||||
:name="t('repod', 'Unread all')"
|
:name="t('repod', 'Unread all')"
|
||||||
:title="t('repod', 'Unread all')"
|
:title="t('repod', 'Unread all')"
|
||||||
@ -58,8 +58,8 @@
|
|||||||
<template #icon>
|
<template #icon>
|
||||||
<NcAvatar
|
<NcAvatar
|
||||||
v-if="
|
v-if="
|
||||||
episodes.filter((e) => e.selected).length <
|
episodes.filter((e: EpisodeInterface) => e.selected)
|
||||||
episodes.length
|
.length < episodes.length
|
||||||
"
|
"
|
||||||
:display-name="t('repod', 'Select all')"
|
:display-name="t('repod', 'Select all')"
|
||||||
:is-no-user="true">
|
:is-no-user="true">
|
||||||
@ -72,8 +72,8 @@
|
|||||||
</NcAvatar>
|
</NcAvatar>
|
||||||
<NcAvatar
|
<NcAvatar
|
||||||
v-if="
|
v-if="
|
||||||
episodes.filter((e) => e.selected).length >=
|
episodes.filter((e: EpisodeInterface) => e.selected)
|
||||||
episodes.length
|
.length >= episodes.length
|
||||||
"
|
"
|
||||||
:display-name="t('repod', 'Unselect all')"
|
:display-name="t('repod', 'Unselect all')"
|
||||||
:is-no-user="true">
|
:is-no-user="true">
|
||||||
@ -89,7 +89,9 @@
|
|||||||
<Episode
|
<Episode
|
||||||
v-for="episode in filteredEpisodes"
|
v-for="episode in filteredEpisodes"
|
||||||
:key="episode.guid"
|
:key="episode.guid"
|
||||||
:display-actions="episodes.every((e) => !e.selected)"
|
:display-actions="
|
||||||
|
episodes.every((e: EpisodeInterface) => !e.selected)
|
||||||
|
"
|
||||||
:episode="episode"
|
:episode="episode"
|
||||||
:url="url"
|
:url="url"
|
||||||
@select="episode.selected = !episode.selected" />
|
@select="episode.selected = !episode.selected" />
|
||||||
@ -137,7 +139,7 @@ export default {
|
|||||||
...mapState(usePlayer, ['episode']),
|
...mapState(usePlayer, ['episode']),
|
||||||
...mapState(useSettings, ['filters']),
|
...mapState(useSettings, ['filters']),
|
||||||
filteredEpisodes() {
|
filteredEpisodes() {
|
||||||
return this.episodes.filter((episode) => {
|
return this.episodes.filter((episode: EpisodeInterface) => {
|
||||||
if (!this.filters.listened && this.hasEnded(episode)) {
|
if (!this.filters.listened && this.hasEnded(episode)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -157,7 +159,7 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
episode() {
|
episode() {
|
||||||
if (this.episode) {
|
if (this.episode) {
|
||||||
this.episodes = this.episodes.map((episode) =>
|
this.episodes = this.episodes.map((episode: EpisodeInterface) =>
|
||||||
episode.url === this.episode?.url ? this.episode : episode,
|
episode.url === this.episode?.url ? this.episode : episode,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -172,7 +174,7 @@ export default {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
this.episodes = [...episodes.data].sort(
|
this.episodes = [...episodes.data].sort(
|
||||||
(a, b) =>
|
(a: EpisodeInterface, b: EpisodeInterface) =>
|
||||||
new Date(b.pubDate?.date || '').getTime() -
|
new Date(b.pubDate?.date || '').getTime() -
|
||||||
new Date(a.pubDate?.date || '').getTime(),
|
new Date(a.pubDate?.date || '').getTime(),
|
||||||
)
|
)
|
||||||
@ -190,14 +192,14 @@ export default {
|
|||||||
t,
|
t,
|
||||||
async read(read: boolean) {
|
async read(read: boolean) {
|
||||||
try {
|
try {
|
||||||
this.episodes = this.episodes.map((episode) =>
|
this.episodes = this.episodes.map((episode: EpisodeInterface) =>
|
||||||
episode.selected ? markAs(episode, read, this.url) : episode,
|
episode.selected ? markAs(episode, read, this.url) : episode,
|
||||||
)
|
)
|
||||||
await axios.post(
|
await axios.post(
|
||||||
generateUrl('/apps/gpoddersync/episode_action/create'),
|
generateUrl('/apps/gpoddersync/episode_action/create'),
|
||||||
this.episodes
|
this.episodes
|
||||||
.filter((episode) => episode.selected)
|
.filter((episode: EpisodeInterface) => episode.selected)
|
||||||
.map((episode) => episode.action),
|
.map((episode: EpisodeInterface) => episode.action),
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
@ -205,7 +207,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
select(all: boolean) {
|
select(all: boolean) {
|
||||||
this.episodes = this.episodes.map((episode) => {
|
this.episodes = this.episodes.map((episode: EpisodeInterface) => {
|
||||||
episode.selected = all
|
episode.selected = all
|
||||||
return episode
|
return episode
|
||||||
})
|
})
|
||||||
|
@ -63,11 +63,11 @@ export default {
|
|||||||
)
|
)
|
||||||
this.episodes = [...episodes.data]
|
this.episodes = [...episodes.data]
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) =>
|
(a: EpisodeInterface, b: EpisodeInterface) =>
|
||||||
new Date(b.pubDate?.date || '').getTime() -
|
new Date(b.pubDate?.date || '').getTime() -
|
||||||
new Date(a.pubDate?.date || '').getTime(),
|
new Date(a.pubDate?.date || '').getTime(),
|
||||||
)
|
)
|
||||||
.filter((episode) => !this.hasEnded(episode))
|
.filter((episode: EpisodeInterface) => !this.hasEnded(episode))
|
||||||
.slice(0, 4)
|
.slice(0, 4)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
@ -39,10 +39,13 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { NcActionButton, NcAppNavigationItem, NcAvatar } from '@nextcloud/vue'
|
import { NcActionButton, NcAppNavigationItem, NcAvatar } from '@nextcloud/vue'
|
||||||
|
import type {
|
||||||
|
PersonalSettingsPodcastDataInterface,
|
||||||
|
SubscriptionInterface,
|
||||||
|
} from '../../utils/types.ts'
|
||||||
import { mapActions, mapState } from 'pinia'
|
import { mapActions, mapState } from 'pinia'
|
||||||
import AlertIcon from 'vue-material-design-icons/Alert.vue'
|
import AlertIcon from 'vue-material-design-icons/Alert.vue'
|
||||||
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
|
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
|
||||||
import type { PersonalSettingsPodcastDataInterface } from '../../utils/types.ts'
|
|
||||||
import StarIcon from 'vue-material-design-icons/Star.vue'
|
import StarIcon from 'vue-material-design-icons/Star.vue'
|
||||||
import StarPlusIcon from 'vue-material-design-icons/StarPlus.vue'
|
import StarPlusIcon from 'vue-material-design-icons/StarPlus.vue'
|
||||||
import StarRemoveIcon from 'vue-material-design-icons/StarRemove.vue'
|
import StarRemoveIcon from 'vue-material-design-icons/StarRemove.vue'
|
||||||
@ -128,7 +131,10 @@ export default {
|
|||||||
},
|
},
|
||||||
switchFavorite(value: boolean) {
|
switchFavorite(value: boolean) {
|
||||||
if (value) {
|
if (value) {
|
||||||
if (this.subs.filter((sub) => sub.isFavorite).length >= 10) {
|
if (
|
||||||
|
this.subs.filter((sub: SubscriptionInterface) => sub.isFavorite)
|
||||||
|
.length >= 10
|
||||||
|
) {
|
||||||
showError(t('repod', 'You can only have 10 favorites'))
|
showError(t('repod', 'You can only have 10 favorites'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import type {
|
import type {
|
||||||
PersonalSettingsMetricsInterface,
|
PersonalSettingsMetricsInterface,
|
||||||
PodcastDataInterface,
|
PodcastDataInterface,
|
||||||
|
PodcastMetricsInterface,
|
||||||
SubscriptionInterface,
|
SubscriptionInterface,
|
||||||
} from '../utils/types.ts'
|
} from '../utils/types.ts'
|
||||||
import { getCookie, setCookie } from '../utils/cookies.ts'
|
import { getCookie, setCookie } from '../utils/cookies.ts'
|
||||||
@ -14,7 +15,7 @@ export const useSubscriptions = defineStore('subscriptions', {
|
|||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getSubByUrl: (state) => (url: string) =>
|
getSubByUrl: (state) => (url: string) =>
|
||||||
state.subs.find((sub) => sub.metrics.url === url),
|
state.subs.find((sub: SubscriptionInterface) => sub.metrics.url === url),
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async fetch() {
|
async fetch() {
|
||||||
@ -28,20 +29,23 @@ export const useSubscriptions = defineStore('subscriptions', {
|
|||||||
)
|
)
|
||||||
|
|
||||||
this.subs = [...metrics.data.subscriptions]
|
this.subs = [...metrics.data.subscriptions]
|
||||||
.sort((a, b) => b.listenedSeconds - a.listenedSeconds)
|
.sort(
|
||||||
.map((sub) => ({
|
(a: PodcastMetricsInterface, b: PodcastMetricsInterface) =>
|
||||||
|
b.listenedSeconds - a.listenedSeconds,
|
||||||
|
)
|
||||||
|
.map((sub: PodcastMetricsInterface) => ({
|
||||||
metrics: sub,
|
metrics: sub,
|
||||||
isFavorite: favorites.includes(sub.url),
|
isFavorite: favorites.includes(sub.url),
|
||||||
data: this.getSubByUrl(sub.url)?.data,
|
data: this.getSubByUrl(sub.url)?.data,
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
addMetadatas(link: string, data: PodcastDataInterface) {
|
addMetadatas(link: string, data: PodcastDataInterface) {
|
||||||
this.subs = this.subs.map((sub) =>
|
this.subs = this.subs.map((sub: SubscriptionInterface) =>
|
||||||
sub.metrics.url === link ? { ...sub, data } : sub,
|
sub.metrics.url === link ? { ...sub, data } : sub,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
setFavorite(link: string, isFavorite: boolean) {
|
setFavorite(link: string, isFavorite: boolean) {
|
||||||
this.subs = this.subs.map((sub) =>
|
this.subs = this.subs.map((sub: SubscriptionInterface) =>
|
||||||
sub.metrics.url === link ? { ...sub, isFavorite } : sub,
|
sub.metrics.url === link ? { ...sub, isFavorite } : sub,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,8 +53,8 @@ export const useSubscriptions = defineStore('subscriptions', {
|
|||||||
'repod.favorites',
|
'repod.favorites',
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
this.subs
|
this.subs
|
||||||
.filter((sub) => sub.isFavorite)
|
.filter((sub: SubscriptionInterface) => sub.isFavorite)
|
||||||
.map((sub) => sub.metrics.url),
|
.map((sub: SubscriptionInterface) => sub.metrics.url),
|
||||||
),
|
),
|
||||||
365,
|
365,
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
export const getCookie = (name: string): string | null => {
|
export const getCookie = (name: string): string | null => {
|
||||||
const cookies = document.cookie.split('; ')
|
const cookies = document.cookie.split('; ')
|
||||||
const value = cookies.find((c) => c.startsWith(name + '='))?.split('=')[1]
|
const value = cookies
|
||||||
|
.find((c: string) => c.startsWith(name + '='))
|
||||||
|
?.split('=')[1]
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import AppContent from '../components/Atoms/AppContent.vue'
|
|||||||
import EmptyContent from '../components/Atoms/EmptyContent.vue'
|
import EmptyContent from '../components/Atoms/EmptyContent.vue'
|
||||||
import Favorite from '../components/Feed/Favorite.vue'
|
import Favorite from '../components/Feed/Favorite.vue'
|
||||||
import StarOffIcon from 'vue-material-design-icons/StarOff.vue'
|
import StarOffIcon from 'vue-material-design-icons/StarOff.vue'
|
||||||
|
import type { SubscriptionInterface } from '../utils/types.ts'
|
||||||
import { mapState } from 'pinia'
|
import { mapState } from 'pinia'
|
||||||
import { t } from '@nextcloud/l10n'
|
import { t } from '@nextcloud/l10n'
|
||||||
import { useSubscriptions } from '../store/subscriptions.ts'
|
import { useSubscriptions } from '../store/subscriptions.ts'
|
||||||
@ -39,7 +40,7 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapState(useSubscriptions, ['subs']),
|
...mapState(useSubscriptions, ['subs']),
|
||||||
favorites() {
|
favorites() {
|
||||||
return this.subs.filter((sub) => sub.isFavorite)
|
return this.subs.filter((sub: SubscriptionInterface) => sub.isFavorite)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user