Merge pull request #2002 from bookwyrm-social/cw-refactor

Refactors content warning field
This commit is contained in:
Mouse Reeve 2022-03-10 14:29:16 -08:00 committed by GitHub
commit f2bf52ccb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 49 deletions

View file

@ -117,7 +117,7 @@
<summary>
<span role="heading" aria-level="3">
{% trans "Add notes" %}
<span class="details-close icon icon-plus" aria-hidden="true"></span>
<span class="details-close icon icon-x" aria-hidden="true"></span>
</span>
</summary>
{% include "lists/edit_item_form.html" with book=item.book %}

View file

@ -1,22 +1,33 @@
{% load i18n %}
<div
class="field{% if not reply_parent.content_warning and not draft.content_warning %} is-hidden{% endif %}"
id="spoilers_{{ uuid }}{{ local_uuid }}"
>
<label
class="label"
for="id_content_warning_{{ uuid }}{{ local_uuid }}"
>
{% trans "Content warning:" %}
</label>
<input
type="text"
name="content_warning"
maxlength="255"
class="input"
id="id_content_warning_{{ uuid }}{{ local_uuid }}"
placeholder="{% trans 'Spoilers ahead!' %}"
value="{% firstof draft.content_warning reply_parent.content_warning '' %}"
{% if not draft %}data-cache-draft="id_content_warning_{{ book.id }}_{{ type }}"{% endif %}
<div class="field is-relative">
<details
{% if reply_parent.content_warning or draft.content_warning %}open{% endif %}
>
<summary class="is-flex">
<span class="icon icon-warning is-size-5 mr-1" aria-hidden="true"></span>
<span>
{% trans "Include spoiler alert" %}
</span>
<span class="details-close icon icon-x" aria-hidden="true"></span>
</summary>
<label
class="label"
for="id_content_warning_{{ uuid }}{{ local_uuid }}"
>
{% trans "Spoilers/content warnings:" %}
</label>
<div class="control">
<input
type="text"
name="content_warning"
maxlength="255"
class="input"
id="id_content_warning_{{ uuid }}{{ local_uuid }}"
placeholder="{% trans 'Spoilers ahead!' %}"
value="{% firstof draft.content_warning reply_parent.content_warning '' %}"
{% if not draft %}data-cache-draft="id_content_warning_{{ book.id }}_{{ type }}"{% endif %}
>
</div>
</details>
</div>

View file

@ -1,17 +0,0 @@
{% load i18n %}
<div class="control">
<input
type="checkbox"
class="is-hidden"
name="sensitive"
id="id_show_spoilers_{{ uuid }}{{ local_uuid }}"
{% if draft.content_warning or status.content_warning %}checked{% endif %}
aria-hidden="true"
{% if not draft %}data-cache-draft="id_sensitive_{{ book.id }}_{{ type }}{{ reply_parent.id }}"{% endif %}
>
{% trans "Include spoiler alert" as button_text %}
{% firstof draft.content_warning status.content_warning as pressed %}
{% firstof local_uuid '' as local_uuid %}
{% include 'snippets/toggle/toggle_button.html' with text=button_text icon="warning is-size-4" controls_text="spoilers" controls_uid=uuid|add:local_uuid focus="id_content_warning" checkbox="id_show_spoilers" class="toggle-button" pressed=pressed %}
</div>

View file

@ -37,8 +37,6 @@ reply_parent: the Status object this post will be in reply to, if applicable
{% endif %}
{% endblock %}
{% include "snippets/create_status/content_warning_field.html" %}
{# fields that go between the content warnings and the content field (ie, quote) #}
{% block pre_content_additions %}{% endblock %}
@ -55,6 +53,8 @@ reply_parent: the Status object this post will be in reply to, if applicable
{# additional fields that go after the content block (ie, progress) #}
{% block post_content_additions %}{% endblock %}
{% include "snippets/create_status/content_warning_field.html" %}
{% block options_block %}
{# cw, post privacy, and submit button #}
{% include "snippets/create_status/post_options_block.html" %}

View file

@ -1,8 +1,6 @@
{% load i18n %}
<div class="columns mt-1">
<div class="field has-addons column">
{% include "snippets/create_status/content_warning_toggle.html" %}
<div class="control">
<div class="field has-addons is-justify-content-end">
<div class="control">
{% if type == 'direct' %}
<input type="hidden" name="privacy" value="direct">
<button type="button" class="button" aria-label="Privacy" disabled>{% trans "Private" %}</button>
@ -13,13 +11,11 @@
{% include 'snippets/privacy_select.html' with current=reply_parent.privacy %}
{% endif %}
{% endif %}
</div>
</div>
<div class="column is-narrow control">
<div class="control">
<button class="button is-link" type="submit">
<span class="icon icon-spinner" aria-hidden="true"></span>
<span>{% trans "Post" %}</span>
</button>
</div>
</div>

View file

@ -85,9 +85,7 @@ class CreateStatus(View):
if hasattr(status, "quote"):
status.raw_quote = status.quote
if not status.sensitive and status.content_warning:
# the cw text field remains populated when you click "remove"
status.content_warning = None
status.sensitive = status.content_warning not in [None, ""]
status.save(broadcast=False)
# inspect the text for user tags