diff --git a/src/digimarks/main.py b/src/digimarks/main.py index 33357eb..a6570e7 100644 --- a/src/digimarks/main.py +++ b/src/digimarks/main.py @@ -362,10 +362,15 @@ def list_bookmarks( session: SessionDep, user_key: str, offset: int = 0, - limit: Annotated[int, Query(le=100)] = 100, + limit: Annotated[int, Query(le=10000)] = 100, ) -> list[Bookmark]: - """List all bookmarks in the database.""" - bookmarks = session.exec(select(Bookmark).where(Bookmark.userkey == user_key).offset(offset).limit(limit)).all() + """List all bookmarks in the database. By default gives back 100 items.""" + bookmarks = session.exec( + select(Bookmark) + .where(Bookmark.userkey == user_key, Bookmark.status != Visibility.DELETED) + .offset(offset) + .limit(limit) + ).all() return bookmarks diff --git a/src/digimarks/static/js/digimarks.js b/src/digimarks/static/js/digimarks.js new file mode 100644 index 0000000..158bc81 --- /dev/null +++ b/src/digimarks/static/js/digimarks.js @@ -0,0 +1,63 @@ +document.addEventListener('alpine:init', () => { + Alpine.store('digimarks', { + /** Main digimarks application, state etc */ + // userKey: Alpine.$persist(0).as('userKey'), + userKey: -1, + /* cache consists of cache[userKey] = {'bookmarks': [], 'tags': [], ??} */ + cache: Alpine.$persist({}).as('cache'), + + bookmarks: [], + tags: [], + + tryout: 'hey', + + loading: false, + + search: '', + + async init() { + /** Initialise the application after loading */ + // if (this.userKey in this.cache) { + // console.log('loading bookmarks from cache'); + // this.bookmarks = this.cache[this.userKey]['bookmarks'] || []; + // } + /* await this.getBookmarks(); */ + setInterval(() => { + // Update counter to next game (midnight UTC, fetched from API) every second + // this.countDownTimer(); + }, 1000); + }, + async loadCache() { + console.log('Loading bookmarks from cache for user "' + this.userKey + '"'); + this.bookmarks = this.cache[this.userKey]['bookmarks'] || []; + + }, + async getBookmarks() { + /** Get the bookmarks from the backend */ + this.loading = true; + console.log('Fetching latest bookmarks from backend for user "' + this.userKey + '"...'); + let response = await fetch('/api/v1/' + this.userKey + '/bookmarks/?limit=10000'); + let result = await response.json(); + console.log(result); + this.bookmarks = result; + if (!(this.userKey in this.cache)) { + /* There is no cache for this userKey yet, create on */ + console.log('caching'); + this.cache[this.userKey] = {'bookmarks': []}; + } + /* Cache the bookmarks to Local Storage */ + this.cache[this.userKey]['bookmarks'] = result; + this.loading = false; + }, + + get filteredItems() { + // return this.cache[this.userKey]['bookmarks'].filter( + // i => i.title.includes(this.search) + // ) + /* Use 'bookmarks' as it can already be pre-filtered */ + return this.bookmarks.filter( + i => i.title.match(new RegExp(this.search, "i")) + ) + } + }) +}); diff --git a/src/digimarks/templates/base.html b/src/digimarks/templates/base.html index 80b5cfb..9d9e427 100644 --- a/src/digimarks/templates/base.html +++ b/src/digimarks/templates/base.html @@ -18,18 +18,17 @@ -
+{% block pagecontent %} +
- {% block pagecontent %} - {% endblock %} +
+{% endblock %} - - + + - {% block extrajs %}{% endblock %} - -
+{% block extrajs %}{% endblock %} diff --git a/src/digimarks/templates/user_index.html b/src/digimarks/templates/user_index.html index b5b66a1..93ed770 100644 --- a/src/digimarks/templates/user_index.html +++ b/src/digimarks/templates/user_index.html @@ -3,8 +3,28 @@ {% block pageheader %}Bookmarks{% endblock %} {% block pagecontent %} - Welcome user! +
-
+ + Welcome user ! Tryout: + +
+ Loading... +
+ + +
{% endblock %}