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,
);