add: questions, requests

This commit is contained in:
trisua 2025-04-12 22:25:54 -04:00
parent 24f67221ca
commit 7960484bf9
52 changed files with 1698 additions and 100 deletions

View file

@ -1,7 +1,8 @@
{% import "components.html" as components %} {% extends "communities/base.html"
%} {% block content %}
<div class="flex flex-col gap-4 w-full">
{% if user and can_post %}
{{ macros::community_nav(community=community, selected="posts") }} {% if
user and can_post %}
<div class="card-nest">
<div class="card small flex items-center gap-2">
{{ icon "pencil" }}
@ -45,7 +46,7 @@
{% if post[0].context.repost and post[0].context.repost.reposting %}
{{ components::repost(repost=post[2], post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{{ components::post(post=post[0], owner=post[1], question=post[3], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{% endif %}
{% endfor %}
</div>
@ -64,7 +65,7 @@
{% if post[0].context.repost and post[0].context.repost.reposting %}
{{ components::repost(repost=post[2], post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{{ components::post(post=post[0], owner=post[1], question=post[3], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{% endif %}
{% endfor %}

View file

@ -14,7 +14,7 @@
{% if post.context.repost and post.context.repost.reposting %}
{{ components::repost(repost=reposting, post=post, owner=owner, community=community, show_community=true, can_manage_post=can_manage_posts) }}
{% else %}
{{ components::post(post=post, owner=owner, community=community, show_community=true, can_manage_post=can_manage_posts) }}
{{ components::post(post=post, owner=owner, question=question, community=community, show_community=true, can_manage_post=can_manage_posts) }}
{% endif %}
</div>
@ -231,7 +231,7 @@
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in replies %}
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false) }}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, show_community=false) }}
{% endfor %}
{{ components::pagination(page=page, items=replies|length) }}

View file

@ -0,0 +1,88 @@
{% extends "root.html" %} {% block head %}
<title>Question - {{ config.name }}</title>
{% endblock %} {% block body %} {{ macros::nav() }}
<main class="flex flex-col gap-2">
<div style="display: contents">
{{ components::question(question=question, owner=owner) }}
</div>
{% if user and (user.id == question.receiver or question.is_global) and not
has_answered %}
<div class="card-nest">
<div class="card small flex items-center gap-2">
{{ icon "square-pen" }}
<b>{{ text "requests:label.answer" }}</b>
</div>
<form
class="card flex flex-col gap-2"
onsubmit="answer_question_from_form(event, '{{ question.id }}')"
>
<div class="flex flex-col gap-1">
<label for="content"
>{{ text "communities:label.content" }}</label
>
<textarea
type="text"
name="content"
id="content"
placeholder="content"
required
minlength="2"
maxlength="4096"
></textarea>
</div>
<button class="primary">
{{ text "communities:action.create" }}
</button>
</form>
</div>
{% endif %}
<div class="card-nest w-full" data-tab="replies">
<div class="card small flex items-center gap-2">
{{ icon "newspaper" }}
<span>{{ text "communities:label.replies" }}</span>
</div>
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in replies %}
{{ components::post(post=post[0], owner=post[1], question=false, secondary=true, show_community=false) }}
{% endfor %}
{{ components::pagination(page=page, items=replies|length) }}
</div>
</div>
</main>
<script>
async function answer_question_from_form(e, answering) {
e.preventDefault();
await trigger("atto::debounce", ["posts::create"]);
fetch("/api/v1/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content: e.target.content.value,
community: "{{ config.town_square }}",
answering,
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
if (res.ok) {
window.location.reload();
}
});
}
</script>
{% endblock %}

View file

@ -0,0 +1,45 @@
{% import "components.html" as components %} {% extends "communities/base.html"
%} {% block content %}
<div class="flex flex-col gap-4 w-full">
{{ macros::community_nav(community=community, selected="questions") }}
<!-- prettier-ignore -->
{% if user and can_post %}
<div style="display: contents">
{{ components::create_question_form(community=community.id,
is_global=true) }}
</div>
{% endif %}
<div class="card-nest">
<div class="card small flex gap-2 items-center">
{{ icon "newspaper" }}
<span>{{ text "communities:label.questions" }}</span>
</div>
<div class="card tertiary flex flex-col gap-4">
<!-- prettier-ignore -->
{% for question in feed %}
<div class="card-nest">
{{ components::question(question=question[0], owner=question[1],
show_community=false) }}
<div class="card flex flex-wrap gap-2">
<a
href="/question/{{ question[0].id }}"
class="button quaternary small"
>
{{ icon "external-link" }} {% if user %}
<span>{{ text "requests:label.answer" }}</span>
{% else %}
<span>{{ text "general:action.open" }}</span>
{% endif %}
</a>
</div>
</div>
{% endfor %} {{ components::pagination(page=page, items=feed|length)
}}
</div>
</div>
</div>
{% endblock %}

View file

@ -567,6 +567,14 @@
"{{ community.context.is_nsfw }}",
"checkbox",
],
[
[
"enable_questions",
"Allow users to ask questions in this community",
],
"{{ community.context.enable_questions }}",
"checkbox",
],
],
settings,
);

View file

@ -143,10 +143,12 @@ community=false, show_community=true, can_manage_post=false) -%}
);
</script>
</div>
{%- endmacro %} {% macro post(post, owner, secondary=false, community=false,
show_community=true, can_manage_post=false) -%} {% if community and
show_community and community.id != config.town_square %}
{%- endmacro %} {% macro post(post, owner, question=false, secondary=false,
community=false, show_community=true, can_manage_post=false) -%} {% if community
and show_community and community.id != config.town_square or question %}
<div class="card-nest">
{% if question %} {{ components::question(question=question[0],
owner=question[1]) }} {% else %}
<div class="card small">
<a
href="/api/v1/communities/find/{{ post.community }}"
@ -167,15 +169,15 @@ show_community and community.id != config.town_square %}
icon "pin" }} {% endif %}
</a>
</div>
{% endif %}
{% endif %} {% endif %}
<div
class="card flex flex-col gap-2 {% if secondary %}secondary{% endif %}"
id="post:{{ post.id }}"
>
<div class="w-full flex gap-2">
<a href="/@{{ owner.username }}">
{{ components::avatar(username=post.owner, size="52px",
selector_type="id") }}
{{ components::avatar(username=owner.username, size="52px",
selector_type="username") }}
</a>
<div class="flex flex-col w-full gap-1">
@ -337,7 +339,8 @@ show_community and community.id != config.town_square %}
</div>
</div>
</div>
{% if community and show_community and community.id != config.town_square %}
{% if community and show_community and community.id != config.town_square or
question %}
</div>
{% endif %} {%- endmacro %} {% macro notification(notification) -%}
<div class="w-full card-nest">
@ -364,7 +367,7 @@ show_community and community.id != config.town_square %}
{% if notification.read %}
<button
class="tertiary"
onclick="trigger('me::update_notification_read_statsu', ['{{ notification.id }}', false])"
onclick="trigger('me::update_notification_read_status', ['{{ notification.id }}', false])"
>
{{ icon "undo" }}
<span>{{ text "notifs:action.mark_as_unread" }}</span>
@ -372,7 +375,7 @@ show_community and community.id != config.town_square %}
{% else %}
<button
class="green tertiary"
onclick="trigger('me::update_notification_read_statsu', ['{{ notification.id }}', true])"
onclick="trigger('me::update_notification_read_status', ['{{ notification.id }}', true])"
>
{{ icon "check" }}
<span>{{ text "notifs:action.mark_as_read" }}</span>
@ -589,4 +592,105 @@ and user %}
]);
}
</script>
{% endif %} {%- endmacro %}
{% endif %} {%- endmacro %} {% macro question(question, owner,
show_community=true, secondary=false) -%}
<div class="card{% if secondary %} secondary{% endif %} flex gap-2">
<a href="/@{{ owner.username }}">
{{ components::avatar(username=owner.username, selector_type="username",
size="52px") }}
</a>
<div class="flex flex-col gap-1">
<div class="flex items-center gap-2 flex-wrap">
<span class="name"
>{{ components::full_username(user=owner) }}</span
>
<span class="date">{{ question.created }}</span>
<span
title="Question"
class="flex items-center"
style="color: var(--color-primary)"
>
{{ icon "message-circle-heart" }}
</span>
{% if question.community > 0 and show_community %}
<a href="/api/v1/communities/find/{{ question.community }}">
{{ components::community_avatar(id=question.community,
size="24px") }}
</a>
{% endif %} {% if question.is_global %}
<a class="notification chip" href="/question/{{ question.id }}"
>{{ question.answer_count }} answers</a
>
{% endif %}
</div>
<span class="no_p_margin" style="font-weight: 500"
>{{ question.content|markdown|safe }}</span
>
<div class="flex gap-2 items-center justify-between"></div>
</div>
</div>
{%- endmacro %} {% macro create_question_form(receiver="0", community="",
is_global=false) -%}
<div class="card-nest">
<div class="card small flex items-center gap-2">
{{ icon "message-circle-heart" }}
<span>{{ text "requests:label.ask_question" }}</span>
</div>
<form
class="card flex flex-col gap-2"
onsubmit="create_question_from_form(event)"
>
<div class="flex flex-col gap-1">
<label for="content">{{ text "communities:label.content" }}</label>
<textarea
type="text"
name="content"
id="content"
placeholder="content"
required
minlength="2"
maxlength="4096"
></textarea>
</div>
<button class="primary">{{ text "communities:action.create" }}</button>
</form>
</div>
<script>
async function create_question_from_form(e) {
e.preventDefault();
await trigger("atto::debounce", ["questions::create"]);
fetch("/api/v1/questions", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content: e.target.content.value,
receiver: "{{ receiver }}",
community: "{{ community }}",
is_global: "{{ is_global }}" == "true",
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
if (res.ok) {
e.target.reset();
}
});
}
</script>
{%- endmacro %}

View file

@ -15,14 +15,6 @@
<span class="desktop">{{ text "general:link.home" }}</span>
</a>
<a
href="/popular"
class="button {% if selected == 'popular' %}active{% endif %}"
>
{{ icon "trending-up" }}
<span class="desktop">{{ text "general:link.popular" }}</span>
</a>
{% if user %}
<a
href="/communities"
@ -46,6 +38,16 @@
{{ icon "square-pen" }}
</a>
<a
href="/requests"
class="button {% if selected == 'requests' %}active{% endif %}"
title="Requests"
>
{{ icon "inbox" }} {% if user.request_count > 0 %}
<span class="notification tr">{{ user.request_count }}</span>
{% endif %}
</a>
<a
href="/notifs"
class="button {% if selected == 'notifications' %}active{% endif %}"
@ -183,4 +185,23 @@
</a>
{% endif %}
</div>
{%- endmacro %}
{%- endmacro %} {% macro community_nav(community, selected="") -%} {% if
community.context.enable_questions %}
<div class="pillmenu">
<a
href="/community/{{ community.title }}"
class="{% if selected == 'posts' %}active{% endif %}"
>
{{ icon "newspaper" }}
<span>{{ text "communities:tab.posts" }}</span>
</a>
<a
href="/community/{{ community.title }}/questions"
class="{% if selected == 'questions' %}active{% endif %}"
>
{{ icon "message-circle-heart" }}
<span>{{ text "communities:tab.questions" }}</span>
</a>
</div>
{% endif %} {%- endmacro %}

View file

@ -11,7 +11,7 @@
<button
onclick="trigger('me::clear_notifs')"
class="small quaternary"
class="small red quaternary"
>
{{ icon "bomb" }}
<span>{{ text "notifs:action.clear" }}</span>

View file

@ -0,0 +1,172 @@
{% extends "root.html" %} {% block head %}
<title>Requests - {{ config.name }}</title>
{% endblock %} {% block body %} {{ macros::nav(selected="requests") }}
<main class="flex flex-col gap-2">
<div class="card-nest">
<div class="card small flex items-center justify-between gap-2">
<span class="flex items-center gap-2">
{{ icon "inbox" }}
<span>{{ text "requests:label.requests" }}</span>
</span>
<button onclick="clear_requests()" class="small red quaternary">
{{ icon "bomb" }}
<span>{{ text "notifs:action.clear" }}</span>
</button>
</div>
<div class="card tertiary flex flex-col gap-4">
{% for request in requests %} {% if request.action_type ==
"CommunityJoin" %}
<div class="card-nest">
<div class="card small flex items-center gap-2">
{{ icon "user-plus" }}
<span
>{{ text "requests:label.community_join_request"
}}</span
>
</div>
<div class="card flex flex-wrap gap-2">
<a
href="/community/{{ request.linked_asset }}/manage?uid={{ request.id }}#/members"
class="button"
>
{{ icon "external-link" }}
<span>{{ text "requests:label.review" }}</span>
</a>
<button
class="quaternary red"
onclick="remove_request('{{ request.id }}', '{{ request.linked_asset }}')"
>
{{ icon "trash" }}
<span>{{ text "general:action.delete" }}</span>
</button>
</div>
</div>
{% endif %} {% endfor %} {% for question in questions %}
<!-- prettier-ignore -->
<div class="card-nest">
{{ components::question(question=question[0], owner=question[1]) }}
<form
class="card flex flex-col gap-2"
onsubmit="answer_question_from_form(event, '{{ question[0].id }}')"
>
<div class="flex flex-col gap-1">
<label for="content">{{ text "communities:label.content" }}</label>
<textarea
type="text"
name="content"
id="content"
placeholder="content"
required
minlength="2"
maxlength="4096"
></textarea>
</div>
<div class="flex gap-2">
<button class="primary">{{ text "requests:label.answer" }}</button>
<button class="red quaternary" onclick="remove_question('{{ question[0].id }}')">{{ text "general:action.delete" }}</button>
</div>
</form>
</div>
{% endfor %}
</div>
</div>
</main>
<script>
async function remove_request(id, linked_asset) {
if (
!(await trigger("atto::confirm", [
"Are you sure you want to do this?",
]))
) {
return;
}
fetch(`/api/v1/requests/${id}/${linked_asset}`, {
method: "DELETE",
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
}
async function clear_requests() {
if (
!(await trigger("atto::confirm", [
"Are you sure you want to do this?",
]))
) {
return;
}
fetch("/api/v1/requests/my", {
method: "DELETE",
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
}
async function remove_question(id) {
if (
!(await trigger("atto::confirm", [
"Are you sure you want to do this?",
]))
) {
return;
}
fetch(`/api/v1/questions/${id}`, {
method: "DELETE",
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
}
async function answer_question_from_form(e, answering) {
e.preventDefault();
await trigger("atto::debounce", ["posts::create"]);
fetch("/api/v1/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content: e.target.content.value,
community: "{{ config.town_square }}",
answering,
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
if (res.ok) {
e.target.parentElement.remove();
}
});
}
</script>
{% endblock %}

View file

@ -121,6 +121,11 @@
<span class="date">{{ profile.created }}</span>
</div>
<div class="w-full flex justify-between items-center">
<span class="notification chip">Posts</span>
<span>{{ profile.post_count }}</span>
</div>
{% if not profile.settings.private_last_seen or is_self
or is_helper %}
<div class="w-full flex justify-between items-center">

View file

@ -1,5 +1,9 @@
{% extends "profile/base.html" %} {% block content %} {% if pinned|length != 0
%}
{% extends "profile/base.html" %} {% block content %} {% if
profile.settings.enable_questions and user %}
<div style="display: contents">
{{ components::create_question_form(receiver=profile.id) }}
</div>
{% endif %} {% if pinned|length != 0 %}
<div class="card-nest">
<div class="card small flex gap-2 items-center">
{{ icon "pin" }}
@ -12,7 +16,7 @@
{% if post[0].context.repost and post[0].context.repost.reposting %}
{{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true, can_manage_post=is_self) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], can_manage_post=is_self) }}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], can_manage_post=is_self) }}
{% endif %}
{% endfor %}
</div>
@ -31,7 +35,7 @@
{% if post[0].context.repost and post[0].context.repost.reposting %}
{{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true, can_manage_post=is_self) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], can_manage_post=is_self) }}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], can_manage_post=is_self) }}
{% endif %}
{% endfor %}

View file

@ -740,6 +740,14 @@
profile_settings,
[
[[], "Privacy", "title"],
[
[
"enable_questions",
"Allow users to ask you questions",
],
"{{ profile.settings.enable_questions }}",
"checkbox",
],
[
[
"private_profile",

View file

@ -10,7 +10,7 @@
{% if post[0].context.repost and post[0].context.repost.reposting %}
{{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2]) }}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2]) }}
{% endif %}
{% endfor %}

View file

@ -10,7 +10,7 @@
{% if post[0].context.repost and post[0].context.repost.reposting %}
{{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2]) }}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2]) }}
{% endif %}
{% endfor %}

View file

@ -28,7 +28,7 @@
{% if post[0].context.repost and post[0].context.repost.reposting %}
{{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2]) }}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2]) }}
{% endif %}
{% endfor %}

View file

@ -10,7 +10,7 @@
{% if post[0].context.repost and post[0].context.repost.reposting %}
{{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2]) }}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2]) }}
{% endif %}
{% endfor %}