1
0
mirror of https://github.com/aquatix/digimarks.git synced 2025-12-06 20:55:10 +01:00

Made code more robust against missing cache items

This commit is contained in:
2025-10-30 16:18:54 +01:00
parent 5eb9c606f0
commit cae9ebf3ef
3 changed files with 48 additions and 37 deletions

View File

@@ -34,6 +34,8 @@ class Settings(BaseSettings):
favicons_dir: DirectoryPath favicons_dir: DirectoryPath
# inside the codebase # inside the codebase
# static_dir: DirectoryPath = Path('digimarks/static')
# template_dir: DirectoryPath = Path('digimarks/templates')
static_dir: DirectoryPath = 'digimarks/static' static_dir: DirectoryPath = 'digimarks/static'
template_dir: DirectoryPath = 'digimarks/templates' template_dir: DirectoryPath = 'digimarks/templates'

View File

@@ -18,6 +18,7 @@ document.addEventListener('alpine:init', () => {
/* Bookmark that is being edited, used to fill the form, etc. */ /* Bookmark that is being edited, used to fill the form, etc. */
bookmarkToEdit: Alpine.$persist({}).as('bookmarkToEdit'), bookmarkToEdit: Alpine.$persist({}).as('bookmarkToEdit'),
bookmarkToEditError: null, bookmarkToEditError: null,
bookmarkToEditVisible: false,
/* Loading indicator */ /* Loading indicator */
loading: false, loading: false,
@@ -147,6 +148,10 @@ document.addEventListener('alpine:init', () => {
) )
}, },
get filteredTags() { get filteredTags() {
if (this.cache[this.userKey].tags === undefined) {
console.log('Tags not yet cached');
return [];
}
/* Search in the list of all tags */ /* Search in the list of all tags */
return this.cache[this.userKey].tags.filter( return this.cache[this.userKey].tags.filter(
i => i.match(new RegExp(this.search, "i")) i => i.match(new RegExp(this.search, "i"))
@@ -214,7 +219,6 @@ document.addEventListener('alpine:init', () => {
'note': '', 'note': '',
'tags': '' 'tags': ''
} }
}, },
async startAddingBookmark() { async startAddingBookmark() {
/* Open 'add bookmark' page */ /* Open 'add bookmark' page */
@@ -222,6 +226,7 @@ document.addEventListener('alpine:init', () => {
this.resetEditBookmark(); this.resetEditBookmark();
// this.show_bookmark_details = true; // this.show_bookmark_details = true;
const editFormDialog = document.getElementById("editFormDialog"); const editFormDialog = document.getElementById("editFormDialog");
this.bookmarkToEditVisible = true;
editFormDialog.showModal(); editFormDialog.showModal();
}, },
async bookmarkURLChanged() { async bookmarkURLChanged() {
@@ -253,6 +258,7 @@ document.addEventListener('alpine:init', () => {
}, },
async saveBookmark() { async saveBookmark() {
console.log('Saving bookmark'); console.log('Saving bookmark');
// this.bookmarkToEditVisible = false;
// this.show_bookmark_details = false; // this.show_bookmark_details = false;
}, },
async addBookmark() { async addBookmark() {

View File

@@ -185,43 +185,46 @@
</span> </span>
</div> </div>
#} #}
<form method="dialog" id="bookmarkEditForm" x-if="$store.digimarks.bookmarkToEdit"> <template x-if="$store.digimarks.bookmarkToEditVisible">
<fieldset class="form-group"> <form method="dialog" id="bookmarkEditForm">
<label for="bookmark_url">URL</label> <fieldset class="form-group">
<input id="bookmark_url" type="text" name="bookmark_url" placeholder="url" <label for="bookmark_url">URL</label>
x-on:change.debounce="$store.digimarks.bookmarkURLChanged()" <input id="bookmark_url" type="text" name="bookmark_url" placeholder="url"
x-model="$store.digimarks.bookmarkToEdit.url"> x-on:change.debounce="$store.digimarks.bookmarkURLChanged()"
</fieldset> x-model="$store.digimarks.bookmarkToEdit.url">
<fieldset class="form-group"> </fieldset>
<label for="bookmark_title">Title</label> <fieldset class="form-group">
<input id="bookmark_title" type="text" name="bookmark_title" <label for="bookmark_title">Title</label>
placeholder="title (leave empty for autofetch)" <input id="bookmark_title" type="text" name="bookmark_title"
x-model="$store.digimarks.bookmarkToEdit.title"> placeholder="title (leave empty for autofetch)"
</fieldset> x-model="$store.digimarks.bookmarkToEdit.title">
<fieldset class="form-group"> </fieldset>
<label for="bookmark_note">Note</label> <fieldset class="form-group">
<textarea id="bookmark_note" type="text" name="bookmark_note" <label for="bookmark_note">Note</label>
x-model="$store.digimarks.bookmarkToEdit.note"> <textarea id="bookmark_note" type="text" name="bookmark_note"
x-model="$store.digimarks.bookmarkToEdit.note">
</textarea> </textarea>
</fieldset> </fieldset>
<fieldset class="form-group"> <fieldset class="form-group">
<label for="bookmark_tags">Tags</label> <label for="bookmark_tags">Tags</label>
<input id="bookmark_tags" type="text" name="bookmark_tags" <input id="bookmark_tags" type="text" name="bookmark_tags"
placeholder="tags, divided bij comma's" placeholder="tags, divided bij comma's"
x-model="$store.digimarks.bookmarkToEdit.tags"> x-model="$store.digimarks.bookmarkToEdit.tags">
</fieldset> </fieldset>
<p x-show="$store.digimarks.bookmarkToEditError" x-data="$store.digimarks.bookmarkToEditError"></p> <p x-show="$store.digimarks.bookmarkToEditError"
<p> x-data="$store.digimarks.bookmarkToEditError"></p>
<label> <p>
<input type="checkbox" name="strip" id="strip"/> <label>
<span>Strip parameters from url (like <em>?utm_source=social</em> - can break the link!)</span> <input type="checkbox" name="strip" id="strip"/>
</label> <span>Strip parameters from url (like <em>?utm_source=social</em> - can break the link!)</span>
</p> </label>
<div> </p>
<button value="cancel">Cancel</button> <div>
<button @click="$store.digimarks.saveBookmark()">Save</button> <button value="cancel">Cancel</button>
</div> <button @click="$store.digimarks.saveBookmark()">Save</button>
</form> </div>
</form>
</template>
</dialog> </dialog>
</main> </main>