add: post drafts
fix: allow question sender to view question
This commit is contained in:
parent
24162573ee
commit
f6cbeb9bd8
22 changed files with 642 additions and 100 deletions
|
@ -187,6 +187,16 @@
|
|||
<span>{{ text "communities:label.chats" }}</span>
|
||||
</a>
|
||||
|
||||
{% if user and can_post %}
|
||||
<a
|
||||
href="/communities/intents/post?community={{ community.id }}"
|
||||
class="button quaternary"
|
||||
>
|
||||
{{ icon "plus" }}
|
||||
<span>{{ text "general:action.post" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
globalThis.leave_community = async () => {
|
||||
if (
|
||||
|
@ -224,6 +234,14 @@
|
|||
{{ icon "message-circle" }}
|
||||
<span>{{ text "communities:label.chats" }}</span>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="/communities/intents/post?community={{ community.id }}"
|
||||
class="button quaternary"
|
||||
>
|
||||
{{ icon "plus" }}
|
||||
<span>{{ text "general:action.post" }}</span>
|
||||
</a>
|
||||
{% endif %} {% if can_manage_community or is_manager %}
|
||||
<a
|
||||
href="/community/{{ community.id }}/manage"
|
||||
|
|
|
@ -2,7 +2,21 @@
|
|||
<title>Create post - {{ config.name }}</title>
|
||||
{% endblock %} {% block body %} {{ macros::nav() }}
|
||||
<main class="flex flex-col gap-2">
|
||||
<div class="card-nest">
|
||||
{% if drafts|length > 0 %}
|
||||
<div class="pillmenu">
|
||||
<a href="#/create" data-tab-button="create" class="active">
|
||||
{{ icon "plus" }}
|
||||
<span>{{ text "general:action.post" }}</span>
|
||||
</a>
|
||||
|
||||
<a href="#/drafts" data-tab-button="drafts">
|
||||
{{ icon "notepad-text-dashed" }}
|
||||
<span>{{ text "communities:label.drafts" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-nest" data-tab="create">
|
||||
<div class="card small flex items-center justify-between gap-2">
|
||||
<span class="flex items-center gap-2">
|
||||
{{ icon "pen" }}
|
||||
|
@ -15,7 +29,33 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
<div class="card tertiary">
|
||||
<div class="card tertiary flex flex-col gap-2">
|
||||
{% if draft %}
|
||||
<div
|
||||
class="card secondary w-full flex items-center justify-between gap-2 small"
|
||||
>
|
||||
<a class="flex items-center gap-2 flush" href="#/drafts">
|
||||
{{ icon "notepad-text-dashed" }}
|
||||
<span class="date">{{ draft.created }}</span>
|
||||
</a>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<a href="?" class="button quaternary small">
|
||||
{{ icon "x" }}
|
||||
<span>{{ text "dialog:action.cancel" }}</span>
|
||||
</a>
|
||||
|
||||
<button
|
||||
class="button quaternary red small"
|
||||
onclick="remove_draft('{{ draft.id }}')"
|
||||
>
|
||||
{{ icon "trash"}}
|
||||
<span>{{ text "general:action.delete" }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-nest">
|
||||
<div class="card small flex flex-row gap-2 items-center">
|
||||
{{ components::avatar(username=user.id, size="32px",
|
||||
|
@ -25,12 +65,18 @@
|
|||
id="community_to_post_to"
|
||||
onchange="update_community_avatar(event)"
|
||||
>
|
||||
<option value="{{ config.town_square }}" selected>
|
||||
<option
|
||||
value="{{ config.town_square }}"
|
||||
selected="{% if not selected_community %}true{% else %}false{% endif %}"
|
||||
>
|
||||
{{ text "auth:link.my_profile" }}
|
||||
</option>
|
||||
|
||||
{% for community in communities %}
|
||||
<option value="{{ community.id }}">
|
||||
<option
|
||||
value="{{ community.id }}"
|
||||
selected="{% if selected_community == community.id %}true{% else %}false{% endif %}"
|
||||
>
|
||||
<!-- prettier-ignore -->
|
||||
{% if community.context.display_name %}
|
||||
{{ community.context.display_name }}
|
||||
|
@ -44,6 +90,7 @@
|
|||
|
||||
<form
|
||||
class="card flex flex-col gap-2"
|
||||
id="create_form"
|
||||
onsubmit="create_post_from_form_town_square(event)"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
|
@ -57,29 +104,55 @@
|
|||
placeholder="content"
|
||||
minlength="2"
|
||||
maxlength="4096"
|
||||
></textarea>
|
||||
>
|
||||
{% if draft %}{{ draft.content }}{% endif %}</textarea
|
||||
>
|
||||
</div>
|
||||
|
||||
<div id="files_list" class="flex gap-2 flex-wrap"></div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
{{ components::emoji_picker(element_id="content",
|
||||
render_dialog=true) }} {% if is_supporter %} {{
|
||||
components::file_picker(files_list_id="files_list") }}
|
||||
{% endif %}
|
||||
<div class="flex justify-between gap-2">
|
||||
<div class="flex gap-2">
|
||||
{{ components::emoji_picker(element_id="content",
|
||||
render_dialog=true) }} {% if is_supporter %} {{
|
||||
components::file_picker(files_list_id="files_list")
|
||||
}} {% endif %}
|
||||
|
||||
<button
|
||||
class="small square quaternary"
|
||||
title="More options"
|
||||
onclick="document.getElementById('post_options_dialog').showModal()"
|
||||
type="button"
|
||||
>
|
||||
{{ icon "ellipsis" }}
|
||||
</button>
|
||||
<button
|
||||
class="small square quaternary"
|
||||
title="More options"
|
||||
onclick="document.getElementById('post_options_dialog').showModal()"
|
||||
type="button"
|
||||
>
|
||||
{{ icon "ellipsis" }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button class="primary">
|
||||
{{ text "communities:action.create" }}
|
||||
</button>
|
||||
<div class="flex gap-2">
|
||||
{% if draft %}
|
||||
<button
|
||||
class="secondary small square"
|
||||
title="Save as Draft"
|
||||
onclick="update_draft('{{ draft.id }}')"
|
||||
type="button"
|
||||
>
|
||||
{{ icon "notepad-text-dashed" }}
|
||||
</button>
|
||||
{% else %}
|
||||
<button
|
||||
class="secondary small square"
|
||||
title="Save as Draft"
|
||||
onclick="create_draft()"
|
||||
type="button"
|
||||
>
|
||||
{{ icon "notepad-text-dashed" }}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
<button class="primary">
|
||||
{{ text "communities:action.create" }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -147,6 +220,23 @@
|
|||
);
|
||||
}
|
||||
|
||||
// remove draft
|
||||
// {% if draft %}
|
||||
if ("{{ draft.id }}") {
|
||||
fetch("/api/v1/drafts/{{ draft.id }}", {
|
||||
method: "DELETE",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
}
|
||||
// {% endif %}
|
||||
|
||||
// ...
|
||||
setTimeout(() => {
|
||||
window.location.href = `/post/${res.payload}`;
|
||||
}, 100);
|
||||
|
@ -157,9 +247,143 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function create_draft() {
|
||||
const e = {
|
||||
target: document.getElementById("create_form"),
|
||||
};
|
||||
|
||||
await trigger("atto::debounce", ["posts::create"]);
|
||||
|
||||
e.target
|
||||
.querySelector("button.primary")
|
||||
.classList.add("hidden");
|
||||
|
||||
fetch("/api/v1/drafts", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: e.target.content.value,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
|
||||
if (res.ok) {
|
||||
setTimeout(() => {
|
||||
window.location.href = `?from_draft=${res.payload}`;
|
||||
}, 100);
|
||||
} else {
|
||||
e.target
|
||||
.querySelector("button.primary")
|
||||
.classList.remove("hidden");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function update_draft(id) {
|
||||
const e = {
|
||||
target: document.getElementById("create_form"),
|
||||
};
|
||||
|
||||
await trigger("atto::debounce", ["posts::create"]);
|
||||
|
||||
e.target
|
||||
.querySelector("button.primary")
|
||||
.classList.add("hidden");
|
||||
|
||||
fetch(`/api/v1/drafts/${id}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: e.target.content.value,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
|
||||
if (!res.ok) {
|
||||
e.target
|
||||
.querySelector("button.primary")
|
||||
.classList.remove("hidden");
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if drafts|length > 0 %}
|
||||
<div class="card-nest tertiary hidden" data-tab="drafts">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "notepad-text-dashed" }}
|
||||
<span>{{ text "communities:label.drafts" }}</span>
|
||||
</div>
|
||||
|
||||
<div class="card flex flex-col gap-2">
|
||||
{% for draft in drafts %}
|
||||
<div class="card-nest">
|
||||
<div class="card small flex flex-col gap-2">
|
||||
<span class="no_p_margin"
|
||||
>{{ draft.content|markdown|safe }}</span
|
||||
>
|
||||
<span class="fade date">{{ draft.created }}</span>
|
||||
</div>
|
||||
|
||||
<div class="card flex gap-2 secondary">
|
||||
<a href="?from_draft={{ draft.id }}" class="button small">
|
||||
{{ icon "pen-line"}}
|
||||
<span>{{ text "communities:label.load" }}</span>
|
||||
</a>
|
||||
|
||||
<button
|
||||
class="button quaternary red small"
|
||||
onclick="remove_draft('{{ draft.id }}')"
|
||||
>
|
||||
{{ icon "trash"}}
|
||||
<span>{{ text "general:action.delete" }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
async function remove_draft(id) {
|
||||
if (
|
||||
!(await trigger("atto::confirm", [
|
||||
"Are you sure you want to do this?",
|
||||
]))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/drafts/${id}`, {
|
||||
method: "DELETE",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
</main>
|
||||
|
||||
<script>
|
||||
|
|
|
@ -2,38 +2,7 @@
|
|||
%} {% block content %}
|
||||
<div class="flex flex-col gap-4 w-full">
|
||||
{{ 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" }}
|
||||
<span>{{ text "communities:label.create_post" }}</span>
|
||||
</div>
|
||||
|
||||
<form
|
||||
class="card flex flex-col gap-2"
|
||||
onsubmit="create_post_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>
|
||||
{% endif %} {% if pinned|length != 0 %}
|
||||
pinned|length != 0 %}
|
||||
<div class="card-nest">
|
||||
<div class="card small flex gap-2 items-center">
|
||||
{{ icon "pin" }}
|
||||
|
@ -73,40 +42,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
async function create_post_from_form(e) {
|
||||
e.preventDefault();
|
||||
await trigger("atto::debounce", ["posts::create"]);
|
||||
|
||||
// create body
|
||||
const body = new FormData();
|
||||
body.append(
|
||||
"body",
|
||||
JSON.stringify({
|
||||
content: e.target.content.value,
|
||||
community: "{{ community.id }}",
|
||||
}),
|
||||
);
|
||||
|
||||
// ...
|
||||
fetch("/api/v1/posts", {
|
||||
method: "POST",
|
||||
body,
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
|
||||
if (res.ok) {
|
||||
setTimeout(() => {
|
||||
window.location.href = `/post/${res.payload}`;
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue