From 0c4785a1e1b66197ee976de00cfda2789928861f Mon Sep 17 00:00:00 2001 From: Qamar Stationwala Date: Tue, 13 Aug 2024 12:27:52 -0700 Subject: [PATCH 1/4] adding bookmarking functionality Signed-off-by: Qamar Stationwala --- ordering/static/js/bookmark-episode.js | 23 +++++++++++++++++++++++ ordering/templates/index.html | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 ordering/static/js/bookmark-episode.js diff --git a/ordering/static/js/bookmark-episode.js b/ordering/static/js/bookmark-episode.js new file mode 100644 index 0000000..f6eab1d --- /dev/null +++ b/ordering/static/js/bookmark-episode.js @@ -0,0 +1,23 @@ +const bookmarkEpisode = ({target}) => { + const { episodeId } = target.dataset + let bookmarks = JSON.parse(localStorage.getItem('bookmarks')) + const index = bookmarks?.indexOf(episodeId) + if (target.checked) { + //add episode to localstorage + if (!bookmarks) bookmarks = [episodeId] //bookmarks array doesnt exist. create it + else { + //check to see if it exists in array already + if (index === -1) {//does not exist, push to array + bookmarks.push(episodeId) + } + else return //already in array, no need to do anything + } + } else { + //remove episode from localstorage + if (!bookmarks || index === -1) return //array does not exist OR does not exist in array, no need to do anything + else { + bookmarks.splice(index, 1) //remove from bookmarks array + } + } + if (bookmarks) localStorage.setItem('bookmarks', JSON.stringify(bookmarks)) //if bookmarks array exists, save it to local storage +} \ No newline at end of file diff --git a/ordering/templates/index.html b/ordering/templates/index.html index d8e8deb..f1e1f28 100644 --- a/ordering/templates/index.html +++ b/ordering/templates/index.html @@ -160,6 +160,7 @@ + @@ -171,6 +172,7 @@ {% for row in table_content %} + @@ -334,6 +336,7 @@ + {% include 'analytics.html' %} From 8458f4ec3495615fb12d352cd3bcb9098252b070 Mon Sep 17 00:00:00 2001 From: Qamar Stationwala Date: Tue, 13 Aug 2024 14:40:15 -0700 Subject: [PATCH 2/4] adding aria label to input Signed-off-by: Qamar Stationwala --- ordering/templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ordering/templates/index.html b/ordering/templates/index.html index f1e1f28..f954819 100644 --- a/ordering/templates/index.html +++ b/ordering/templates/index.html @@ -172,7 +172,7 @@ {% for row in table_content %} - + From 9ae7ac8233fe34dbe461e08d458f49b1a7e4a524 Mon Sep 17 00:00:00 2001 From: Qamar Stationwala Date: Wed, 14 Aug 2024 01:20:20 -0700 Subject: [PATCH 3/4] bookmarks need to be initialized on load as well, or else the whole thing is pointless Signed-off-by: Qamar Stationwala --- ordering/static/js/bookmark-episode.js | 6 ++++++ ordering/templates/index.html | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ordering/static/js/bookmark-episode.js b/ordering/static/js/bookmark-episode.js index f6eab1d..ac48bb6 100644 --- a/ordering/static/js/bookmark-episode.js +++ b/ordering/static/js/bookmark-episode.js @@ -20,4 +20,10 @@ const bookmarkEpisode = ({target}) => { } } if (bookmarks) localStorage.setItem('bookmarks', JSON.stringify(bookmarks)) //if bookmarks array exists, save it to local storage +} + +const setupBookmarks = () => { + const elems = document.querySelectorAll('input[type="checkbox"]') // get all inputs + const bookmarks = JSON.parse(localStorage.getItem('bookmarks')) //get bookmarks from local storage + for (const elem in elems) if (bookmarks && bookmarks.indexOf(elem.dataset.episodeId) !== -1) elem.checked = true //loop through inputs, if bookmarks exist and episode id is found in array, set checked to true } \ No newline at end of file diff --git a/ordering/templates/index.html b/ordering/templates/index.html index f954819..7e10655 100644 --- a/ordering/templates/index.html +++ b/ordering/templates/index.html @@ -26,7 +26,7 @@ {% include 'ads.html' %} - + {% if using_old_site %}
@@ -172,7 +172,7 @@
{% for row in table_content %} - + From 7fb578b578dd7c7f5b506fdb93b6b7b48f390585 Mon Sep 17 00:00:00 2001 From: Qamar Stationwala Date: Wed, 14 Aug 2024 01:20:51 -0700 Subject: [PATCH 4/4] forgot to save index template Signed-off-by: Qamar Stationwala --- ordering/templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ordering/templates/index.html b/ordering/templates/index.html index 7e10655..1df5d4d 100644 --- a/ordering/templates/index.html +++ b/ordering/templates/index.html @@ -172,7 +172,7 @@ {% for row in table_content %} - +
# Series Episode
{{ row.row_number }} {{ row.series }} {{ row.episode_id }}
{{ row.row_number }} {{ row.series }} {{ row.episode_id }}
{{ row.row_number }} {{ row.series }} {{ row.episode_id }}
{{ row.row_number }} {{ row.series }} {{ row.episode_id }}