2023-07-10 00:25:32 +02:00
|
|
|
<template>
|
2024-05-06 12:47:47 +00:00
|
|
|
<NcAppNavigationItem
|
|
|
|
:loading="loading"
|
|
|
|
:name="feed ? feed.title : url"
|
|
|
|
:to="hash">
|
2023-07-25 22:19:16 +02:00
|
|
|
<template #actions>
|
2024-08-17 17:56:12 +02:00
|
|
|
<NcActionButton
|
|
|
|
:aria-label="t('repod', 'Favorite')"
|
|
|
|
:model-value="isFavorite"
|
|
|
|
:name="t('repod', 'Favorite')"
|
|
|
|
:title="t('repod', 'Favorite')"
|
|
|
|
@update:modelValue="switchFavorite($event)">
|
|
|
|
<template #icon>
|
|
|
|
<StarPlusIcon v-if="!isFavorite" :size="20" />
|
|
|
|
<StarRemoveIcon v-if="isFavorite" :size="20" />
|
|
|
|
</template>
|
|
|
|
</NcActionButton>
|
2024-04-30 00:48:47 +02:00
|
|
|
<NcActionButton
|
|
|
|
:aria-label="t(`core`, 'Delete')"
|
2024-03-05 11:39:16 +01:00
|
|
|
:name="t(`core`, 'Delete')"
|
|
|
|
:title="t(`core`, 'Delete')"
|
|
|
|
@click="deleteSubscription">
|
2023-07-25 22:19:16 +02:00
|
|
|
<template #icon>
|
2024-03-16 18:35:31 +01:00
|
|
|
<DeleteIcon :size="20" />
|
2023-07-25 22:19:16 +02:00
|
|
|
</template>
|
|
|
|
</NcActionButton>
|
|
|
|
</template>
|
2024-01-30 18:11:50 +01:00
|
|
|
<template #icon>
|
2024-04-30 00:48:47 +02:00
|
|
|
<NcAvatar
|
|
|
|
v-if="feed"
|
2024-01-30 18:11:50 +01:00
|
|
|
:display-name="feed.author || feed.title"
|
|
|
|
:is-no-user="true"
|
|
|
|
:url="feed.imageUrl" />
|
2024-08-17 17:56:12 +02:00
|
|
|
<StarIcon v-if="feed && isFavorite" class="star" :size="20" />
|
2024-03-16 18:35:31 +01:00
|
|
|
<AlertIcon v-if="failed" />
|
2024-01-30 18:11:50 +01:00
|
|
|
</template>
|
2023-07-10 00:25:32 +02:00
|
|
|
</NcAppNavigationItem>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-07-29 17:53:51 +02:00
|
|
|
import { NcActionButton, NcAppNavigationItem, NcAvatar } from '@nextcloud/vue'
|
2024-08-17 17:56:12 +02:00
|
|
|
import { mapActions, mapState } from 'pinia'
|
2024-03-16 18:35:31 +01:00
|
|
|
import AlertIcon from 'vue-material-design-icons/Alert.vue'
|
|
|
|
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
|
2024-08-17 17:56:12 +02:00
|
|
|
import StarIcon from 'vue-material-design-icons/Star.vue'
|
|
|
|
import StarPlusIcon from 'vue-material-design-icons/StarPlus.vue'
|
|
|
|
import StarRemoveIcon from 'vue-material-design-icons/StarRemove.vue'
|
2023-07-10 00:25:32 +02:00
|
|
|
import axios from '@nextcloud/axios'
|
|
|
|
import { generateUrl } from '@nextcloud/router'
|
2024-08-08 22:39:43 +02:00
|
|
|
import { showError } from '../../utils/toast.js'
|
2024-01-11 22:03:32 +01:00
|
|
|
import { toUrl } from '../../utils/url.js'
|
2024-08-09 09:38:00 +00:00
|
|
|
import { useSubscriptions } from '../../store/subscriptions.js'
|
2023-07-10 00:25:32 +02:00
|
|
|
|
|
|
|
export default {
|
2023-08-23 10:11:39 +02:00
|
|
|
name: 'Item',
|
2023-07-10 00:25:32 +02:00
|
|
|
components: {
|
2024-03-16 18:35:31 +01:00
|
|
|
AlertIcon,
|
|
|
|
DeleteIcon,
|
2023-07-25 22:19:16 +02:00
|
|
|
NcActionButton,
|
2023-07-10 00:25:32 +02:00
|
|
|
NcAppNavigationItem,
|
2023-07-29 17:53:51 +02:00
|
|
|
NcAvatar,
|
2024-08-17 17:56:12 +02:00
|
|
|
StarIcon,
|
|
|
|
StarPlusIcon,
|
|
|
|
StarRemoveIcon,
|
2023-07-10 00:25:32 +02:00
|
|
|
},
|
|
|
|
props: {
|
2023-08-01 23:18:37 +02:00
|
|
|
url: {
|
2023-07-10 00:25:32 +02:00
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
failed: false,
|
|
|
|
loading: true,
|
2023-07-29 17:53:51 +02:00
|
|
|
feed: null,
|
2023-07-10 00:25:32 +02:00
|
|
|
}
|
|
|
|
},
|
2024-01-14 00:33:23 +01:00
|
|
|
computed: {
|
2024-08-17 17:56:12 +02:00
|
|
|
...mapState(useSubscriptions, ['favorites']),
|
2024-01-14 00:33:23 +01:00
|
|
|
hash() {
|
|
|
|
return toUrl(this.url)
|
|
|
|
},
|
2024-08-17 17:56:12 +02:00
|
|
|
isFavorite() {
|
|
|
|
return this.favorites.includes(this.url)
|
|
|
|
},
|
2024-01-14 00:33:23 +01:00
|
|
|
},
|
2023-07-10 00:25:32 +02:00
|
|
|
async mounted() {
|
|
|
|
try {
|
2024-04-30 00:48:47 +02:00
|
|
|
const podcastData = await axios.get(
|
2024-05-06 12:47:47 +00:00
|
|
|
generateUrl(
|
|
|
|
'/apps/gpoddersync/personal_settings/podcast_data?url={url}',
|
|
|
|
{
|
|
|
|
url: this.url,
|
|
|
|
},
|
|
|
|
),
|
2024-04-30 00:48:47 +02:00
|
|
|
)
|
2023-07-29 17:53:51 +02:00
|
|
|
this.feed = podcastData.data.data
|
2023-07-10 00:25:32 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.failed = true
|
|
|
|
console.error(e)
|
|
|
|
} finally {
|
|
|
|
this.loading = false
|
|
|
|
}
|
|
|
|
},
|
2023-07-25 22:19:16 +02:00
|
|
|
methods: {
|
2024-08-17 17:56:12 +02:00
|
|
|
...mapActions(useSubscriptions, ['fetch', 'addFavorite', 'removeFavorite']),
|
2023-07-25 22:19:16 +02:00
|
|
|
async deleteSubscription() {
|
2024-05-06 12:47:47 +00:00
|
|
|
if (
|
|
|
|
confirm(
|
|
|
|
t('repod', 'Are you sure you want to delete this subscription?'),
|
|
|
|
)
|
|
|
|
) {
|
2024-01-10 16:36:37 +01:00
|
|
|
try {
|
|
|
|
this.loading = true
|
2024-04-30 00:48:47 +02:00
|
|
|
await axios.post(
|
|
|
|
generateUrl('/apps/gpoddersync/subscription_change/create'),
|
|
|
|
{ add: [], remove: [this.url] },
|
|
|
|
)
|
2024-01-10 16:36:37 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
showError(t('repod', 'Error while removing the feed'))
|
|
|
|
} finally {
|
2024-08-17 17:56:12 +02:00
|
|
|
this.removeFavorite(this.url)
|
2024-01-10 16:36:37 +01:00
|
|
|
this.loading = false
|
2024-08-09 09:38:00 +00:00
|
|
|
this.fetch()
|
2024-01-10 16:36:37 +01:00
|
|
|
}
|
2023-07-25 22:19:16 +02:00
|
|
|
}
|
|
|
|
},
|
2024-08-17 17:56:12 +02:00
|
|
|
switchFavorite(value) {
|
|
|
|
if (value) {
|
|
|
|
if (this.favorites.length >= 10) {
|
|
|
|
showError(t('repod', 'You can only have 10 favorites'))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addFavorite(this.url)
|
|
|
|
} else {
|
|
|
|
this.removeFavorite(this.url)
|
|
|
|
}
|
|
|
|
},
|
2023-07-25 22:19:16 +02:00
|
|
|
},
|
2023-07-10 00:25:32 +02:00
|
|
|
}
|
|
|
|
</script>
|
2024-08-17 17:56:12 +02:00
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.star {
|
|
|
|
bottom: 2px;
|
|
|
|
color: yellow;
|
|
|
|
left: 22px;
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
</style>
|