1
1
<template >
2
2
<form class =" flexline" @submit.prevent =" addbookmark" >
3
- <input type =" text" v-model =" bookmarkname" :placeholder =" $t('sensorpopup.bookmarkplaceholder')" @input =" IsBookmarked = false" />
4
- <button :class =" buttonclasses" :disabled =" IsBookmarked" :area-label =" $t('sensorpopup.bookmarkbutton')" >
5
- <template v-if =" ! IsBookmarked " ><font-awesome-icon icon =" fa-solid fa-bookmark" /></template >
3
+ <input
4
+ type =" text"
5
+ v-model =" bookmarkname"
6
+ :placeholder =" $t('sensorpopup.bookmarkplaceholder')"
7
+ @input =" IsBookmarked = false"
8
+ />
9
+ <button
10
+ :class =" buttonclasses"
11
+ :disabled =" IsBookmarked"
12
+ :area-label =" $t('sensorpopup.bookmarkbutton')"
13
+ >
14
+ <template v-if =" ! IsBookmarked "
15
+ ><font-awesome-icon icon =" fa-solid fa-bookmark"
16
+ /></template >
6
17
<template v-else ><font-awesome-icon icon =" fa-solid fa-check" /></template >
7
18
</button >
8
19
</form >
@@ -13,7 +24,7 @@ import { useStore } from "@/store";
13
24
import { IDBgettable , IDBworkflow } from " ../../idb" ;
14
25
15
26
export default {
16
- props: [" address" , " link" , " geo" ],
27
+ props: [" address" , " link" , " geo" , " id " ],
17
28
18
29
data () {
19
30
return {
@@ -33,77 +44,93 @@ export default {
33
44
[` button-green` ]: this .IsBookmarked ,
34
45
// [`flexline`]: true,
35
46
};
36
- }
47
+ },
37
48
},
38
49
39
50
methods: {
40
-
41
51
async findbookmark () {
42
- const bookmarks = await IDBgettable (this .store .idbBookmarkDbname , this .store .idbBookmarkVDbver , this .store .idbBookmarkVDbtable )
43
- return bookmarks .find (bookmark => bookmark .address === this .$props .address )
52
+ const bookmarks = await IDBgettable (
53
+ this .store .idbBookmarkDbname ,
54
+ this .store .idbBookmarkVDbver ,
55
+ this .store .idbBookmarkVDbtable
56
+ );
57
+ return bookmarks .find ((bookmark ) => bookmark .id === this .$props .id );
44
58
},
45
59
46
60
async addbookmark () {
47
-
48
61
const bookmark = await this .findbookmark ();
49
62
50
- if (bookmark) {
51
- if (this .bookmarkid ) {
52
-
53
- IDBworkflow (this .store .idbBookmarkDbname , this .store .idbBookmarkVDbver , this .store .idbBookmarkVDbtable , ' readwrite' , store => {
54
- const request = store .get (this .bookmarkid );
55
-
56
- request .addEventListener (' error' , e => {
57
- console .log (e)
58
- })
63
+ if (bookmark) {
64
+ if (this .bookmarkid ) {
65
+ IDBworkflow (
66
+ this .store .idbBookmarkDbname ,
67
+ this .store .idbBookmarkVDbver ,
68
+ this .store .idbBookmarkVDbtable ,
69
+ " readwrite" ,
70
+ (store ) => {
71
+ const request = store .get (this .bookmarkid );
72
+
73
+ request .addEventListener (" error" , (e ) => {
74
+ console .log (e);
75
+ });
59
76
60
- request .addEventListener (' success' , e => {
61
- const data = e .target .result ;
62
- data .customName = this .bookmarkname ;
63
- const requestUpdate = store .put (data);
77
+ request .addEventListener (" success" , ( e ) => {
78
+ const data = e .target .result ;
79
+ data .customName = this .bookmarkname ;
80
+ const requestUpdate = store .put (data);
64
81
65
- requestUpdate .addEventListener (' error' , e => {
66
- console .log (e)
67
- })
82
+ requestUpdate .addEventListener (" error" , ( e ) => {
83
+ console .log (e);
84
+ });
68
85
69
- requestUpdate .addEventListener (' success' , e => {
70
- this .IsBookmarked = true
71
- })
72
- })
73
- })
86
+ requestUpdate .addEventListener (" success" , (e ) => {
87
+ this .IsBookmarked = true ;
88
+ });
89
+ });
90
+ }
91
+ );
74
92
}
75
93
} else {
76
- IDBworkflow (this .store .idbBookmarkDbname , this .store .idbBookmarkVDbver , this .store .idbBookmarkVDbtable , ' readwrite' , store => {
94
+ IDBworkflow (
95
+ this .store .idbBookmarkDbname ,
96
+ this .store .idbBookmarkVDbver ,
97
+ this .store .idbBookmarkVDbtable ,
98
+ " readwrite" ,
99
+ (store ) => {
77
100
store .add ({
78
101
customName: this .bookmarkname ,
102
+ id: this .$props .id ,
79
103
address: this .$props .address ,
80
104
link: this .$props .link ,
81
- geo: JSON .stringify (this .$props .geo )
105
+ geo: JSON .stringify (this .$props .geo ),
82
106
});
83
107
this .IsBookmarked = true ;
84
- })
85
- }
108
+ }
109
+ );
110
+ }
86
111
87
- const bc = new BroadcastChannel (this .store .idbWatcherBroadcast )
88
- bc .postMessage (this .store .idbBookmarkVDbtable )
89
- bc .close ()
112
+ const bc = new BroadcastChannel (this .store .idbWatcherBroadcast );
113
+ bc .postMessage (this .store .idbBookmarkVDbtable );
114
+ bc .close ();
90
115
},
91
116
},
92
117
93
118
async mounted () {
94
119
const bookmark = await this .findbookmark ();
95
- if (bookmark) {
120
+ if (bookmark) {
96
121
this .IsBookmarked = true ;
97
122
this .bookmarkid = bookmark .id ;
98
123
this .bookmarkname = bookmark .customName ;
99
124
}
100
- }
101
- }
125
+
126
+ console .log (this .$props );
127
+ },
128
+ };
102
129
</script >
103
130
104
131
<style scoped>
105
132
button {
106
- padding-right : calc (var (--app-inputpadding )* 2 );
107
- padding-left : calc (var (--app-inputpadding )* 2 );
133
+ padding-right : calc (var (--app-inputpadding ) * 2 );
134
+ padding-left : calc (var (--app-inputpadding ) * 2 );
108
135
}
109
- </style >
136
+ </style >
0 commit comments