Skip to content

Commit 476ea72

Browse files
committed
Migrate PageBookmarkPrompt to Composition API
1 parent 30b71f2 commit 476ea72

File tree

5 files changed

+137
-151
lines changed

5 files changed

+137
-151
lines changed

src/renderer/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import FtToast from './components/ft-toast/ft-toast.vue'
1010
import FtProgressBar from './components/FtProgressBar/FtProgressBar.vue'
1111
import FtPlaylistAddVideoPrompt from './components/ft-playlist-add-video-prompt/ft-playlist-add-video-prompt.vue'
1212
import FtCreatePlaylistPrompt from './components/ft-create-playlist-prompt/ft-create-playlist-prompt.vue'
13-
import PageBookmarkPrompt from './components/page-bookmark-prompt/page-bookmark-prompt.vue'
13+
import PageBookmarkPrompt from './components/PageBookmarkPrompt/PageBookmarkPrompt.vue'
1414
import FtSearchFilters from './components/FtSearchFilters/FtSearchFilters.vue'
1515
import { marked } from 'marked'
1616
import { IpcChannels } from '../constants'
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<template>
2+
<FtPrompt
3+
:label="title"
4+
@click="hide"
5+
>
6+
<h2 class="heading">
7+
{{ title }}
8+
</h2>
9+
<div
10+
class="pageBookmarkDetails"
11+
>
12+
<FtInput
13+
ref="pageBookmarkNameInput"
14+
class="pageBookmarkNameInput"
15+
:placeholder="t('Name')"
16+
:value="name"
17+
:show-clear-text-button="true"
18+
:show-action-button="false"
19+
@input="e => handleNameChange(e)"
20+
@clear="e => handleNameChange('')"
21+
@keydown.enter.native="save"
22+
/>
23+
<FtFlexBox v-if="duplicateNameCount > 0">
24+
<p>{{ $tc('Page Bookmark["There is {count} other bookmark with the same name."]', duplicateNameCount, { count: duplicateNameCount }) }}</p>
25+
</FtFlexBox>
26+
</div>
27+
<div>
28+
<FtFlexBox class="actions-container">
29+
<FtButton
30+
v-if="!isBookmarkBeingCreated"
31+
:label="t('Page Bookmark.Remove Bookmark')"
32+
:icon="['fas', 'trash']"
33+
text-color="var(--destructive-text-color)"
34+
background-color="var(--destructive-color)"
35+
@click="removeBookmark"
36+
/>
37+
<FtButton
38+
:label="t('Save')"
39+
:disabled="name === ''"
40+
text-color="var(--text-with-accent-color)"
41+
background-color="var(--accent-color)"
42+
@click="save"
43+
/>
44+
<FtButton
45+
:label="t('Cancel')"
46+
:text-color="null"
47+
:background-color="null"
48+
@click="hide"
49+
/>
50+
</FtFlexBox>
51+
</div>
52+
</FtPrompt>
53+
</template>
54+
55+
<script setup>
56+
57+
import { computed, nextTick, onMounted, ref } from 'vue'
58+
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
59+
import FtPrompt from '../ft-prompt/ft-prompt.vue'
60+
import FtButton from '../ft-button/ft-button.vue'
61+
import FtInput from '../ft-input/ft-input.vue'
62+
import packageDetails from '../../../../package.json'
63+
import { showToast } from '../../helpers/utils'
64+
import { useI18n } from '../../composables/use-i18n-polyfill'
65+
import { useRouter } from 'vue-router/composables'
66+
import store from '../../store'
67+
68+
const router = useRouter()
69+
70+
const { t } = useI18n()
71+
72+
const existingPageBookmark = computed(() => store.getters.getPageBookmarkWithRoute(router.currentRoute.fullPath))
73+
74+
const appTitle = computed(() => store.getters.getAppTitle.replace(` - ${packageDetails.productName}`, ''))
75+
76+
const isBookmarkBeingCreated = computed(() => existingPageBookmark.value == null)
77+
78+
const pageBookmarks = computed(() => store.getters.getPageBookmarks)
79+
80+
const duplicateNameCount = computed(() => {
81+
const currentBookmarkAdjustment = name.value === existingPageBookmark.value?.name ? -1 : 0
82+
return currentBookmarkAdjustment + pageBookmarks.value.filter((pageBookmark) => pageBookmark.name === name.value).length
83+
})
84+
85+
const title = computed(() => isBookmarkBeingCreated.value ? t('Page Bookmark.Create Bookmark') : t('Page Bookmark.Edit Bookmark'))
86+
87+
const pageBookmarkNameInput = ref(null)
88+
89+
const name = ref('')
90+
91+
function hide() {
92+
store.dispatch('hidePageBookmarkPrompt')
93+
}
94+
95+
function removeBookmark() {
96+
const pageBookmark = existingPageBookmark.value
97+
store.dispatch('removePageBookmark', pageBookmark._id)
98+
showToast(t('Page Bookmark.Removed page bookmark', { name: pageBookmark.name }))
99+
hide()
100+
}
101+
102+
function save() {
103+
if (name.value === '') {
104+
return
105+
}
106+
107+
const pageBookmark = {
108+
route: router.currentRoute.fullPath,
109+
name: name.value,
110+
isBookmark: true
111+
}
112+
113+
if (isBookmarkBeingCreated.value) {
114+
store.dispatch('createPageBookmark', pageBookmark)
115+
showToast(t('Page Bookmark.Created page bookmark', { name: name.value }))
116+
} else if (pageBookmark.name !== existingPageBookmark.value.name) {
117+
store.dispatch('updatePageBookmark', pageBookmark)
118+
showToast(t('Page Bookmark.Updated page bookmark', { name: name.value }))
119+
}
120+
121+
hide()
122+
}
123+
124+
function handleNameChange(input) {
125+
name.value = input
126+
}
127+
128+
onMounted(() => {
129+
nextTick(() => {
130+
name.value = existingPageBookmark.value?.name ?? appTitle.value
131+
pageBookmarkNameInput.value?.focus()
132+
})
133+
})
134+
</script>
135+
136+
<style scoped src="./PageBookmarkPrompt.css" />

src/renderer/components/page-bookmark-prompt/page-bookmark-prompt.js

Lines changed: 0 additions & 94 deletions
This file was deleted.

src/renderer/components/page-bookmark-prompt/page-bookmark-prompt.vue

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)