Skip to main content

add a command to jump to the next unreviewed photo

ID
cd5c2e5
date
2023-05-15 19:49:44+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
3de7e94
message
add a command to jump to the next unreviewed photo

closes #1
changed files
4 files, 27 additions, 19 deletions

Changed files

README.md (3129) → README.md (3184)

diff --git a/README.md b/README.md
index 07b4512..9d430a7 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ I can use the following commands:
 *   `f` – mark the photo as a favourite
 *   `c` – add the photo to my "Cross stitch" album
 *   `o` – open the photo in Photos.app
+*   `u` – jump to the next photo which is unreviewed
 
 
 

server.py (6867) → server.py (6988)

diff --git a/server.py b/server.py
index f374888..628c446 100755
--- a/server.py
+++ b/server.py
@@ -80,19 +80,6 @@ class PhotosData:
         this_asset = all_assets[position]
         next_five = all_assets[position + 1 : position + 6]
 
-        if this_asset["state"] != "Unknown":
-            unreviewed_assets = [
-                asset
-                for i, asset in enumerate(self.all_assets)
-                if i < position and asset["state"] == "Unknown"
-            ]
-            try:
-                next_asset_id_to_review = unreviewed_assets[-1]["localIdentifier"]
-            except IndexError:
-                pass
-        else:
-            next_asset_id_to_review = None
-
         states = collections.Counter(asset["state"] for asset in self.all_assets)
 
         return render_template(
@@ -102,7 +89,6 @@ class PhotosData:
             prev_five=prev_five,
             this_asset=this_asset,
             next_five=next_five,
-            next_asset_id_to_review=next_asset_id_to_review,
             states=states,
         )
 
@@ -221,6 +207,28 @@ def open_photo():
     return b"", 204
 
 
+@app.route("/next-unreviewed")
+def next_unreviewed():
+    local_identifier = request.args['before']
+
+    all_assets = photos_data.all_assets
+
+    position = photos_data.all_positions[local_identifier]
+
+    this_asset = photos_data.all_assets[position]
+
+    unreviewed_assets = [
+        asset
+        for i, asset in enumerate(photos_data.all_assets)
+        if i <= position and asset["state"] == "Unknown"
+    ]
+    try:
+        next_asset_id_to_review = unreviewed_assets[-1]["localIdentifier"]
+        return redirect(url_for('index', localIdentifier=next_asset_id_to_review))
+    except IndexError:
+        return b"", 404
+
+
 @app.route("/refresh", methods=["POST"])
 def refresh():
     photos_data.fetch_metadata()

static/reviewer.js (1179) → static/reviewer.js (1276)

diff --git a/static/reviewer.js b/static/reviewer.js
index c6d125d..23e2d54 100644
--- a/static/reviewer.js
+++ b/static/reviewer.js
@@ -40,4 +40,8 @@ function handleKeyDown(event, thisIdentifier, nextIdentifier, prevIdentifier) {
     case "o":
       httpPOST(`/open?localIdentifier=${thisIdentifier}`);
       break;
+
+    case "u":
+      window.location = `/next-unreviewed?before=${thisIdentifier}`;
+      break;
   }}

templates/index.html (5415) → templates/index.html (5245)

diff --git a/templates/index.html b/templates/index.html
index f74ef60..6342c05 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -16,11 +16,6 @@
     <li>
       <a href="#" onclick="httpPOST('/refresh'); window.location.reload();">refresh photos metadata</a>
     </li>
-    {% if next_asset_id_to_review %}
-    <li>
-      <a href="/?localIdentifier={{ next_asset_id_to_review }}">jump to next unreviewed photo</a>
-    </li>
-    {% endif %}
   </ul>
 </details>