Skip to content

Commit

Permalink
v2: post/redirect/get mark-as-... functionality. #318
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon24 committed Jan 6, 2025
1 parent be4fd90 commit e65951f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 deletions.
36 changes: 34 additions & 2 deletions src/reader/_app/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from functools import partial

from flask import abort
from flask import Blueprint
from flask import redirect
from flask import request

from .. import get_reader
Expand All @@ -22,9 +24,9 @@ def entries():
# TODO: if search/tags is active, search/tags box should not be hidden
# TODO: highlight active filter preset + uncollapse more
# TODO: feed filter
# TODO: pagination
# TODO: paqgination
# TODO: read time
# TODO: mark as ...
# TODO: htmx mark as ...

form = EntryFilter(request.args)
kwargs = dict(form.data)
Expand All @@ -40,3 +42,33 @@ def entries():
return stream_template(
'v2/entries.html', presets=ENTRY_FILTER_PRESETS, form=form, entries=entries
)


@blueprint.route('/mark-as', methods=['POST'])
def mark_as():
reader = get_reader()

entry = request.form['feed-url'], request.form['entry-id']

if 'read' in request.form:
match request.form['read']:
case 'true':
reader.set_entry_read(entry, True)
case 'false':
reader.set_entry_read(entry, False)
case _:
abort(422)

if 'important' in request.form:
match request.form['important']:
case 'true':
reader.set_entry_important(entry, True)
case 'false':
reader.set_entry_important(entry, False)
case 'none':
reader.set_entry_important(entry, None)
case _:
abort(422)

print(request.form['next'])
return redirect(request.form['next'], code=303)
39 changes: 32 additions & 7 deletions src/reader/_app/v2/templates/v2/entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@


{% for entry in entries %}
<div class="mb-4">
<div class="mb-4" id="entry-{{ loop.index }}">

<ul class="list-inline" style="margin-bottom: 0.125rem">

Expand Down Expand Up @@ -95,19 +95,37 @@ <h2 class="h5 mb-1" style="font-size: 1.125rem">
</p>
{% endif %}

<form class="my-2">
{# TODO: aria stuff #}
<form action="{{ url_for('.mark_as') }}" method="post" class="my-2">
{#- TODO: aria stuff #}

<button type="submit" class="btn btn-outline-secondary btn-sm" style="width: 4rem">
<button type="submit" name="read"
value="{{ 'false' if entry.read else 'true' }}"
class="btn btn-outline-secondary btn-sm{% if entry.read %} active{% endif %}"
{% if entry.read -%}
aria-pressed="true"
{% endif -%}
style="width: 4rem">
<i class="bi bi-check-lg"></i>
</button>

<div class="btn-group" role="group" aria-label="importance">
<button type="submit" class="btn btn-outline-secondary btn-sm" style="width: 2rem">
<i class="bi bi-star"></i>
<button type="submit" name="important"
value="{{ 'none' if entry.important is true else 'true' }}"
class="btn btn-outline-secondary btn-sm {% if entry.important is true %} active{% endif %}"
{% if entry.important is true -%}
aria-pressed="true"
{% endif -%}
style="width: 2rem">
<i class="bi {{ 'bi-star-fill' if entry.important is true else 'bi-star' }}"></i>
</button>

<button type="submit" class="btn btn-outline-secondary btn-sm" style="width: 2rem">
<button type="submit" name="important"
value="{{ 'none' if entry.important is false else 'false' }}"
class="btn btn-outline-secondary btn-sm {% if entry.important is false %} active{% endif %}"
{% if entry.important is false -%}
aria-pressed="true"
{% endif -%}
style="width: 2rem">
<i class="bi bi-arrow-down"></i>
</button>
</div>
Expand All @@ -122,6 +140,13 @@ <h2 class="h5 mb-1" style="font-size: 1.125rem">
</a>
{%- endfor %}

<input type="hidden" name="feed-url" value="{{ entry.feed_url }}">
<input type="hidden" name="entry-id" value="{{ entry.id }}">

{% set next = loop.index if not loop.last else loop.index - 1 -%}
<input type="hidden" name="next"
value="{{ url_for('.entries', **request.args) }}#entry-{{ next }}">

</form>

</div>
Expand Down

0 comments on commit e65951f

Please sign in to comment.