Skip to content

Commit 74591d0

Browse files
add @type Bookmark
1 parent d347b6e commit 74591d0

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

bookmark.html

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,20 @@
147147
async loadBookmarks() {
148148
const storage = this.getStorageProvider()
149149
const bookmarks = await storage.load()
150-
this.setState({ bookmarks })
150+
151+
// Ensure all bookmarks have the @type property
152+
const updatedBookmarks = bookmarks.map(bookmark => ({
153+
...bookmark,
154+
'@type': bookmark['@type'] || 'Bookmark'
155+
}))
156+
157+
this.setState({ bookmarks: updatedBookmarks })
151158
console.log(`Bookmarks loaded from ${storage.type}`)
159+
160+
// Save if any bookmarks were updated with @type
161+
if (JSON.stringify(bookmarks) !== JSON.stringify(updatedBookmarks)) {
162+
this.saveBookmarks()
163+
}
152164
}
153165

154166
handleInputChange = e => {
@@ -180,7 +192,8 @@
180192
title,
181193
url: formattedUrl,
182194
createdAt: new Date().toISOString(),
183-
read: false
195+
read: false,
196+
'@type': 'Bookmark'
184197
}
185198
]
186199

@@ -244,38 +257,30 @@ <h2 class="text-2xl font-semibold text-indigo-700 mb-4">
244257
</h2>
245258
<form onSubmit=${this.addBookmark} class="space-y-4">
246259
<div>
247-
<label
248-
class="block text-sm font-medium text-indigo-600 mb-1"
249-
>Title</label
250-
>
251260
<input
252261
type="text"
253262
name="title"
254263
value=${this.state.newBookmark.title}
255264
onInput=${this.handleInputChange}
256-
class="w-full px-4 py-2 rounded-md border border-indigo-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
257-
placeholder="Website Name"
265+
class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:outline-none focus:ring-2 focus:ring-indigo-400 focus:border-transparent"
266+
placeholder="Website Title"
258267
required
259268
/>
260269
</div>
261270
<div>
262-
<label
263-
class="block text-sm font-medium text-indigo-600 mb-1"
264-
>URL</label
265-
>
266271
<input
267272
type="text"
268273
name="url"
269274
value=${this.state.newBookmark.url}
270275
onInput=${this.handleInputChange}
271-
class="w-full px-4 py-2 rounded-md border border-indigo-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
272-
placeholder="https://example.com"
276+
class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:outline-none focus:ring-2 focus:ring-indigo-400 focus:border-transparent"
277+
placeholder="Website URL"
273278
required
274279
/>
275280
</div>
276281
<button
277282
type="submit"
278-
class="w-full bg-gradient-to-r from-blue-400 to-indigo-500 text-white py-2 px-4 rounded-md hover:from-blue-500 hover:to-indigo-600 transition duration-300 ease-in-out transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-indigo-500"
283+
class="w-full bg-indigo-500 text-white py-3 px-4 rounded-lg hover:bg-indigo-600 transition duration-300 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-500"
279284
>
280285
Add Bookmark
281286
</button>

0 commit comments

Comments
 (0)