summaryrefslogtreecommitdiffstats
path: root/src/components/SidebarFeedLinkActions.vue
blob: e9f8bd5212e3e2948928e3ef66b21602abb6eb09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<template>
	<span>
		<NcActionButton v-if="feed.unreadCount > 0"
			icon="icon-checkmark"
			@click="markRead">
			{{ t("news", "Mark read") }}
		</NcActionButton>
		<NcActionButton v-if="feed.pinned"
			icon="icon-pinned"
			@click="setPinned(false)">
			{{ t("news", "Unpin from top") }}
		</NcActionButton>
		<NcActionButton v-if="!feed.pinned"
			icon="icon-pinned"
			@click="setPinned(true)">
			{{ t("news", "Pin to top") }}
		</NcActionButton>
		<NcActionButton v-if="feed.ordering === FEED_ORDER.NEWEST"
			icon="icon-caret-dark"
			@click="setOrdering(FEED_ORDER.OLDEST)">
			{{ t("news", "Newest first") }}
		</NcActionButton>
		<NcActionButton v-else-if="feed.ordering === FEED_ORDER.OLDEST"
			icon="icon-caret-dark"
			@click="setOrdering(FEED_ORDER.DEFAULT)">
			{{ t("news", "Oldest first") }}
		</NcActionButton>
		<NcActionButton v-else
			icon="icon-caret-dark"
			@click="setOrdering(FEED_ORDER.NEWEST)">
			{{ t("news", "Default order") }}
		</NcActionButton>
		<NcActionButton v-if="!feed.fullTextEnabled"
			icon="icon-full-text-disabled"
			@click="setFullText(true)">
			{{ t("news", "Enable full text") }}
		</NcActionButton>
		<NcActionButton v-if="feed.fullTextEnabled"
			icon="icon-full-text-enabled"
			@click="setFullText(false)">
			{{ t("news", "Disable full text") }}
		</NcActionButton>
		<NcActionButton v-if="feed.updateMode === FEED_UPDATE_MODE.UNREAD"
			icon="icon-updatemode-default"
			@click="setUpdateMode(FEED_UPDATE_MODE.IGNORE)">
			{{ t("news", "Unread updated") }}
		</NcActionButton>
		<NcActionButton v-if="feed.updateMode === FEED_UPDATE_MODE.IGNORE"
			icon="icon-updatemode-unread"
			@click="setUpdateMode(FEED_UPDATE_MODE.UNREAD)">
			{{ t("news", "Ignore updated") }}
		</NcActionButton>
		<NcActionButton icon="icon-rename"
			@click="rename()">
			{{ t("news", "Rename") }}
		</NcActionButton>
		<NcActionButton icon="icon-delete"
			@click="deleteFeed()">
			{{ t("news", "Delete") }}
		</NcActionButton>
		<NcAppNavigationItem :title="t('news', 'Open Feed URL')"
			:href="feed.location">
			<template #icon>
				<RssIcon />
			</template>
		</NcAppNavigationItem>

	</span>
</template>

<script lang="ts">

import { mapState } from 'vuex'
import Vue from 'vue'

import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcAppNavigationItem from '@nextcloud/vue/dist/Components/NcAppNavigationItem.js'

import { FEED_ORDER, FEED_UPDATE_MODE } from '../dataservices/feed.service'

import RssIcon from 'vue-material-design-icons/Rss.vue'

import { ACTIONS } from '../store'
import { Feed } from '../types/Feed'

export default Vue.extend({
	components: {
		NcActionButton,
		NcAppNavigationItem,
		RssIcon,
	},
	props: {
		feedId: {
			type: Number,
			required: true,
		},
	},
	data: () => {
		return {
			FEED_ORDER,
			FEED_UPDATE_MODE,
		}
	},

	computed: {
		feed(): Feed {
			return this.$store.getters.feeds.find((feed: Feed) => {
				return feed.id === this.feedId
			})
		},
	},
	methods: {
		alert(msg: string) {
			window.alert(msg)
		},
		markRead() {
			this.$store.dispatch(ACTIONS.FEED_MARK_READ, { feed: this.feed })
		},
		setPinned(pinned: boolean) {
			this.$store.dispatch(ACTIONS.FEED_SET_PINNED, { feed: this.feed, pinned })
		},
		setOrdering(ordering: FEED_ORDER) {
			this.$store.dispatch(ACTIONS.FEED_SET_ORDERING, { feed: this.feed, ordering })
		},
		setFullText(fullTextEnabled: boolean) {
			this.$store.dispatch(ACTIONS.FEED_SET_FULL_TEXT, { feed: this.feed, fullTextEnabled })
		},
		setUpdateMode(updateMode: FEED_UPDATE_MODE) {
			this.$store.dispatch(ACTIONS.FEED_SET_UPDATE_MODE, { feed: this.feed, updateMode })
		},
		rename() {
			const title = window.prompt(t('news', 'Rename Feed'), this.feed.title)

			// null on escape
			if (title !== null) {
				this.$store.dispatch(ACTIONS.FEED_SET_TITLE, { feed: this.feed, title })
			}
		},
		deleteFeed() {
			const shouldDelete = window.confirm(t('news', 'Are you sure you want to delete?'))

			if (shouldDelete) {
				this.$store.dispatch(ACTIONS.FEED_DELETE, { feed: this.feed })
			}
		},
	},
})

</script>