-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddFeedDialog.vue
More file actions
67 lines (62 loc) · 2.31 KB
/
AddFeedDialog.vue
File metadata and controls
67 lines (62 loc) · 2.31 KB
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
<template>
<v-dialog v-model="showAddFeedDialog" activator="parent" :persistent="loadingAddFeed">
<v-card>
<v-card-title class="text-h5">הוספת מקור חדש</v-card-title>
<v-progress-linear v-if="loadingAddFeed" color="green" indeterminate />
<v-form @submit.prevent="addFeed">
<v-card-text>
<v-text-field autofocus v-model="newFeedUrl" label="כתובת המקור" variant="outlined" type="url"
:rules="[val => !!val || 'שדה חובה', val => validator.isURL(val) || 'כתובת לא תקינה']"
:disabled="loadingAddFeed"></v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn variant="text" @click="showAddFeedDialog = false" :disabled="loadingAddFeed">
ביטול
</v-btn>
<v-btn color="green-darken-1" variant="text" type="submit" :disabled="loadingAddFeed">
הוספה
</v-btn>
</v-card-actions>
</v-form>
</v-card>
</v-dialog>
</template>
<script setup>
import { ref, watch } from 'vue'
import { useFeedsStore } from '@/stores/feeds'
import { useSnacksStore } from '@/stores/snacks'
import validator from 'validator'
const snacksStore = useSnacksStore()
const feedsStore = useFeedsStore()
const loadingAddFeed = ref(false)
const showAddFeedDialog = ref(false)
const newFeedUrl = ref('')
const addFeed = async () => {
if (!validator.isURL(newFeedUrl.value)) return;
loadingAddFeed.value = true
try {
if (!/feed|rss|xml$/.test(newFeedUrl.value)) {
newFeedUrl.value = newFeedUrl.value.replace(/\/$/, '') + '/feed'
}
await feedsStore.createFeed(newFeedUrl.value)
showAddFeedDialog.value = false
snacksStore.addSnack({
text: 'המקור נוסף בהצלחה',
color: 'success'
})
} catch (error) {
snacksStore.addSnack({
text: error.message,
color: 'error'
})
} finally {
loadingAddFeed.value = false
}
}
watch(showAddFeedDialog, (val) => {
if (!val.value) {
newFeedUrl.value = ''
}
})
</script>