diff --git a/tildes/tildes/templates/intercooler/post_action_toggle_button.jinja2 b/tildes/tildes/templates/intercooler/post_action_toggle_button.jinja2 index 48d0f36..e2ca3b2 100644 --- a/tildes/tildes/templates/intercooler/post_action_toggle_button.jinja2 +++ b/tildes/tildes/templates/intercooler/post_action_toggle_button.jinja2 @@ -3,4 +3,4 @@ {% from 'macros/buttons.jinja2' import post_action_toggle_button with context %} -{{ post_action_toggle_button("bookmark", subject, is_toggled) }} +{{ post_action_toggle_button(name, subject, is_toggled) }} diff --git a/tildes/tildes/templates/macros/buttons.jinja2 b/tildes/tildes/templates/macros/buttons.jinja2 index a847057..afd4c67 100644 --- a/tildes/tildes/templates/macros/buttons.jinja2 +++ b/tildes/tildes/templates/macros/buttons.jinja2 @@ -12,6 +12,16 @@ {% if name == "bookmark" %} {% set normal_label = "Bookmark" %} {% set toggled_label = "Unbookmark" %} + {% elif name == "lock" %} + {% set normal_label = "Lock" %} + {% set toggled_label = "Unlock" %} + {% set normal_confirm = "Lock this topic?" %} + {% set toggled_confirm = "Unlock this topic?" %} + {% elif name == "remove" %} + {% set normal_label = "Remove" %} + {% set toggled_label = "Un-remove" %} + {% set normal_confirm = "Remove this " + type_name + "?" %} + {% set toggled_confirm = "Un-remove this " + type_name + "?" %} {% endif %}
  • @@ -19,11 +29,13 @@ {% else %} {% endif %}
  • diff --git a/tildes/tildes/templates/macros/comments.jinja2 b/tildes/tildes/templates/macros/comments.jinja2 index f234e33..a69b7de 100644 --- a/tildes/tildes/templates/macros/comments.jinja2 +++ b/tildes/tildes/templates/macros/comments.jinja2 @@ -212,27 +212,7 @@ {% endif %} {% if request.has_permission("remove", comment) %} -
  • - {% if not comment.is_removed %} - - {% else %} - - {% endif %} -
  • + {{ post_action_toggle_button("remove", comment, comment.is_removed) }} {% endif %} {% if request.has_permission('reply', comment) %} diff --git a/tildes/tildes/templates/topic.jinja2 b/tildes/tildes/templates/topic.jinja2 index 66a256b..f725421 100644 --- a/tildes/tildes/templates/topic.jinja2 +++ b/tildes/tildes/templates/topic.jinja2 @@ -141,27 +141,7 @@ {% endif %} {% if request.has_permission('lock', topic) %} -
  • - {% if not topic.is_locked %} - - {% else %} - - {% endif %} -
  • + {{ post_action_toggle_button("lock", topic, topic.is_locked) }} {% endif %} {% if request.has_permission('bookmark', topic) %} @@ -169,27 +149,7 @@ {% endif %} {% if request.has_permission("remove", topic) %} -
  • - {% if not topic.is_removed %} - - {% else %} - - {% endif %} -
  • + {{ post_action_toggle_button("remove", topic, topic.is_removed) }} {% endif %}
    diff --git a/tildes/tildes/views/api/web/comment.py b/tildes/tildes/views/api/web/comment.py index aded654..45e1020 100644 --- a/tildes/tildes/views/api/web/comment.py +++ b/tildes/tildes/views/api/web/comment.py @@ -398,28 +398,36 @@ def put_mark_comments_read(request: Request, mark_all_previous: bool) -> Respons return IC_NOOP -@ic_view_config(route_name="comment_remove", request_method="PUT", permission="remove") -def put_comment_remove(request: Request) -> Response: +@ic_view_config( + route_name="comment_remove", + request_method="PUT", + permission="remove", + renderer="post_action_toggle_button.jinja2", +) +def put_comment_remove(request: Request) -> dict: """Remove a comment with Intercooler.""" comment = request.context comment.is_removed = True request.db_session.add(LogComment(LogEventType.COMMENT_REMOVE, request, comment)) - return Response("Removed") + return {"name": "remove", "subject": comment, "is_toggled": True} @ic_view_config( - route_name="comment_remove", request_method="DELETE", permission="remove" + route_name="comment_remove", + request_method="DELETE", + permission="remove", + renderer="post_action_toggle_button.jinja2", ) -def delete_comment_remove(request: Request) -> Response: +def delete_comment_remove(request: Request) -> dict: """Un-remove a comment with Intercooler.""" comment = request.context comment.is_removed = False request.db_session.add(LogComment(LogEventType.COMMENT_UNREMOVE, request, comment)) - return Response("Un-removed") + return {"name": "remove", "subject": comment, "is_toggled": False} @ic_view_config( diff --git a/tildes/tildes/views/api/web/topic.py b/tildes/tildes/views/api/web/topic.py index 962cfba..98bcd88 100644 --- a/tildes/tildes/views/api/web/topic.py +++ b/tildes/tildes/views/api/web/topic.py @@ -236,48 +236,68 @@ def patch_move_topic(request: Request, path: str) -> dict: return Response("Moved") -@ic_view_config(route_name="topic_remove", request_method="PUT", permission="remove") -def put_topic_remove(request: Request) -> Response: +@ic_view_config( + route_name="topic_remove", + request_method="PUT", + permission="remove", + renderer="post_action_toggle_button.jinja2", +) +def put_topic_remove(request: Request) -> dict: """Remove a topic with Intercooler.""" topic = request.context topic.is_removed = True request.db_session.add(LogTopic(LogEventType.TOPIC_REMOVE, request, topic)) - return Response("Removed") + return {"name": "remove", "subject": topic, "is_toggled": True} -@ic_view_config(route_name="topic_remove", request_method="DELETE", permission="remove") -def delete_topic_remove(request: Request) -> Response: +@ic_view_config( + route_name="topic_remove", + request_method="DELETE", + permission="remove", + renderer="post_action_toggle_button.jinja2", +) +def delete_topic_remove(request: Request) -> dict: """Un-remove a topic with Intercooler.""" topic = request.context topic.is_removed = False request.db_session.add(LogTopic(LogEventType.TOPIC_UNREMOVE, request, topic)) - return Response("Un-removed") + return {"name": "remove", "subject": topic, "is_toggled": False} -@ic_view_config(route_name="topic_lock", request_method="PUT", permission="lock") -def put_topic_lock(request: Request) -> Response: +@ic_view_config( + route_name="topic_lock", + request_method="PUT", + permission="lock", + renderer="post_action_toggle_button.jinja2", +) +def put_topic_lock(request: Request) -> dict: """Lock a topic with Intercooler.""" topic = request.context topic.is_locked = True request.db_session.add(LogTopic(LogEventType.TOPIC_LOCK, request, topic)) - return Response("Locked") + return {"name": "lock", "subject": topic, "is_toggled": True} -@ic_view_config(route_name="topic_lock", request_method="DELETE", permission="lock") -def delete_topic_lock(request: Request) -> Response: +@ic_view_config( + route_name="topic_lock", + request_method="DELETE", + permission="lock", + renderer="post_action_toggle_button.jinja2", +) +def delete_topic_lock(request: Request) -> dict: """Unlock a topic with Intercooler.""" topic = request.context topic.is_locked = False request.db_session.add(LogTopic(LogEventType.TOPIC_UNLOCK, request, topic)) - return Response("Unlocked") + return {"name": "lock", "subject": topic, "is_toggled": False} @ic_view_config(