blob: 045b5f17b50e3f3956a0f3a1c7c303ab896ac7b5 (
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
<script setup>
import { DashboardLayout, FloatingLabelInput, LoadingConditional, SubscriptionEntry } from '@/components';
import { useLogger } from '@/logger.js'
import { ref, onMounted } from 'vue';
import { getTitles, putSubscriptions, postSubscriptions } from '@/api/pse-squared.js'
import { Modal } from 'bootstrap';
const titles = ref(null);
const received = ref(false);
const newSubscription = ref();
const deletedSubscriptions = ref([]);
const { subscriptionAdded } = useLogger();
// if called from pseudo-protocol: show dialog to add subscription up front
onMounted(() => {
loadData();
const urlParams = new URLSearchParams(window.location.search);
const addSubModal = new Modal("#add-sub");
if (urlParams.has('add')) {
newSubscription.value = decodeURIComponent(urlParams.get('add'))
.replace("web+pod://", "");
addSubModal.show();
}
});
// fetches all titles of the subscribed podcasts and sets visibility
async function loadData() {
try {
const response = await getTitles();
received.value = true;
titles.value = response.data;
} catch(err) { }
}
// makes a addition request based in the url in the input field/pseudo protocoll
async function addSubscription() {
received.value = false;
await putSubscriptions([newSubscription.value]);
// log.append({type: "info", message: "Subscription got added to your list!"});
subscriptionAdded();
newSubscription.value = "";
await loadData();
}
// toggles the selection of all subscriptions
function selectAllSubscriptions() {
if ( deletedSubscriptions.value.length > 0 ) {
deletedSubscriptions.value = [];
} else {
deletedSubscriptions.value = titles.value;
}
}
// makes a deletion request from all selected podcasts
async function unsubscribeFromSelected() {
received.value = false;
await postSubscriptions({
add: [],
remove: deletedSubscriptions.value.map(e => e.url)
});
deletedSubscriptions.value = [];
await loadData();
}
// the modal gets open by the id from the html attributes defined in the Subscription
// component.
function unsubscribeSingle(sub) {
deletedSubscriptions.value = [sub];
}
</script>
<template>
<DashboardLayout>
<h1 class="h1 mb-4">
{{ $t("message.yourSubscriptions") }}
</h1>
<!-- add a new subscription by url -->
<form
class="input-group mb-3"
@submit.prevent="addSubscription"
>
<FloatingLabelInput
v-model="newSubscription"
:label="$t('message.newSubscription')"
/>
<button
class="btn btn-success"
type="submit"
>
{{ $t("message.addSubscription") }}
</button>
</form>
<LoadingConditional :waiting-for="received">
<!-- user does not have subscriptions yet -->
<p v-if="titles.length == 0">
{{ $t("message.noSubscriptions") }}
</p>
<!-- display subscriptions -->
<div v-else>
<button
class="btn m-2 btn-success"
@click="selectAllSubscriptions"
>
{{ $t('message.selectAll') }}
</button>
<button
class="btn m-2 btn-primary"
:class="{disabled: deletedSubscriptions.length == 0}"
data-bs-toggle="modal"
data-bs-target="#delete-subs"
>
{{ $t('message.unsubscribeSelected') }}
</button>
<div id="episodes-accordion">
<div
v-for="sub in titles"
:key="sub.url"
class="form-check"
>
<input
v-model="deletedSubscriptions"
class="form-check-input mt-4"
type="checkbox"
:value="sub"
>
<SubscriptionEntry
:sub="sub"
@unsubscribe="unsubscribeSingle"
/>
</div>
</div>
</div>
</LoadingConditional>
</DashboardLayout>
<!-- Modal for adding subscription with pseudo-protocol -->
<div
id="add-sub"
class="modal"
tabindex="-1"
>
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<!-- Title of Modal -->
<div class="modal-header">
<h5 class="modal-title">
{{ $t('message.newSubscription') }}
</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
/>
</div>
<!-- display URL of Podcast to subcribe to -->
<div class="modal-body">
<FloatingLabelInput
v-model="newSubscription"
:label="$t('message.newSubscription')"
/>
</div>
<!-- buttons to dismiss or accept the new subscription -->
<div class="modal-footer">
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>
{{ $t('message.close') }}
</button>
<button
type="button"
data-bs-dismiss="modal"
class="btn btn-primary"
@click="addSubscription"
>
{{ $t('message.addSubscription') }}
</button>
</div>
</div>
</div>
</div>
<!-- Modal for confirming deletion of subscriptions -->
<div
id="delete-subs"
class="modal"
tabindex="-1"
>
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<!-- Title of Modal -->
<div class="modal-header">
<h5 class="modal-title">
{{ $t('message.unsubscribePodcasts') }}
</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
/>
</div>
<!-- list podcasts to unsubscribe from -->
<div class="modal-body">
<div
class="alert alert-warning d-flex align-items-center"
role="alert"
>
<i class="fs-2 me-3 fa fa-warning" />
<div>
{{ $t('message.unsubscribePodcastsWarning') }}
</div>
</div>
<ul>
<li
v-for="sub in deletedSubscriptions"
:key="sub.url"
>
{{ sub.title || sub.url }}
<span class="opacity-50">
({{ $t('message.episode', sub.episodes.length) }})
</span>
</li>
</ul>
</div>
<!-- buttons to dismiss or finaly unsubscribe -->
<div class="modal-footer">
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>
{{ $t('message.close') }}
</button>
<button
type="button"
data-bs-dismiss="modal"
class="btn btn-primary"
@click="unsubscribeFromSelected"
>
{{ $t('message.unsubscribePodcasts') }}
</button>
</div>
</div>
</div>
</div>
</template>
<style scoped>
</style>
|