add: channels, messages

This commit is contained in:
trisua 2025-04-27 23:11:37 -04:00
parent 67492cf73f
commit 7774124bd0
40 changed files with 2238 additions and 115 deletions

View file

@ -179,6 +179,14 @@
<span>{{ text "communities:action.leave" }}</span>
</button>
<a
href="/chats/{{ community.id }}/0"
class="button quaternary"
>
{{ icon "message-circle" }}
<span>{{ text "communities:label.chats" }}</span>
</a>
<script>
globalThis.leave_community = async () => {
if (

View file

@ -17,6 +17,13 @@
{{ icon "users-round" }}
<span>{{ text "communities:tab.members" }}</span>
</a>
{% if can_manage_channels %}
<a href="#/channels" data-tab-button="channels">
{{ icon "rss" }}
<span>{{ text "communities:tab.channels" }}</span>
</a>
{% endif %}
</div>
<div class="w-full flex flex-col gap-2" data-tab="general">
@ -254,6 +261,182 @@
<div class="card flex flex-col gap-2 w-full" id="membership_info"></div>
</div>
{% if can_manage_channels %}
<div
class="card tertiary w-full hidden flex flex-col gap-2"
data-tab="channels"
>
<div class="card-nest">
<div class="card small">
<b>{{ text "communities:action.create_channel" }}</b>
</div>
<form
class="card flex flex-col gap-2"
onsubmit="create_channel_from_form(event)"
>
<div class="flex flex-col gap-1">
<label for="title"
>{{ text "communities:label.name" }}</label
>
<input
type="text"
name="title"
id="title"
placeholder="name"
required
minlength="2"
maxlength="32"
/>
</div>
<button class="primary">
{{ text "communities:action.create" }}
</button>
</form>
</div>
{% for channel in channels %}
<div class="card-nest">
<div class="card small">
<b>{{ channel.position }}</b>
{{ channel.title }}
</div>
<div class="card flex gap-2">
<button
class="red quaternary small"
onclick="delete_channel('{{ channel.id }}')"
>
{{ text "general:action.delete" }}
</button>
<button
class="quaternary small"
onclick="update_channel_position('{{ channel.id }}')"
>
{{ text "chats:action.move" }}
</button>
<button
class="quaternary small"
onclick="update_channel_title('{{ channel.id }}')"
>
{{ text "chats:action.rename" }}
</button>
</div>
</div>
{% endfor %}
</div>
<script>
globalThis.delete_channel = async (id) => {
if (
!(await trigger("atto::confirm", [
"Are you sure you would like to do this?",
]))
) {
return;
}
fetch(`/api/v1/channels/${id}`, {
method: "DELETE",
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
};
globalThis.update_channel_position = async (id) => {
await trigger("atto::debounce", ["channels::move"]);
const position = Number.parseInt(
await trigger("atto::prompt", [
"New channel position (number):",
]),
);
if (!position && position !== 0) {
return alert("Must be a number!");
}
fetch(`/api/v1/channels/${id}/move`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
position,
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
};
globalThis.update_channel_title = async (id) => {
await trigger("atto::debounce", ["channels::update_title"]);
const title = await trigger("atto::prompt", ["New channel title:"]);
if (!title) {
return;
}
fetch(`/api/v1/channels/${id}/title`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title,
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
};
async function create_channel_from_form(e) {
e.preventDefault();
await trigger("atto::debounce", ["channels::create"]);
fetch("/api/v1/channels", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: e.target.title.value,
community: "{{ community.id }}",
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
if (res.ok) {
window.location.reload();
}
});
}
</script>
{% endif %}
</main>
<script>