Merge branch 'guild-settings' into guild-joining
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful

This commit is contained in:
SauceyRed 2025-07-13 01:44:43 +02:00
commit cf32b62ae7
Signed by: sauceyred
GPG key ID: 270B096EF6E9A462
67 changed files with 2621 additions and 255 deletions

View file

@ -0,0 +1,17 @@
import { render } from "vue";
import ContextMenu from "~/components/ContextMenu.vue";
import type { ContextMenuItem } from "~/types/interfaces";
export default (e: MouseEvent, menuItems: ContextMenuItem[]) => {
console.log("Rendering new context menu");
const menuContainer = document.createElement("div");
menuContainer.id = "context-menu";
document.body.appendChild(menuContainer);
const contextMenu = h(ContextMenu, {
menuItems,
cursorX: e.clientX,
cursorY: e.clientY
});
render(contextMenu, menuContainer);
console.log("Rendered");
}

24
utils/editMessage.ts Normal file
View file

@ -0,0 +1,24 @@
import type { MessageProps } from "~/types/props";
export default async (element: HTMLDivElement, props: MessageProps) => {
console.log("message:", element);
const me = await fetchWithApi("/me") as any;
if (props.author?.uuid == me.uuid) {
const text = element.getElementsByClassName("message-text")[0] as HTMLDivElement;
text.contentEditable = "true";
text.focus();
const range = document.createRange();
range.selectNodeContents(text);
range.collapse(false);
const selection = window.getSelection();
selection?.removeAllRanges();
selection?.addRange(range);
element.addEventListener("keyup", (e) => {
console.log("key released:", e.key);
if (e.key == "Escape") {
text.contentEditable = "false";
}
text.blur();
}, { once: true });
}
}

View file

@ -18,7 +18,7 @@ export default async <T>(path: string, options: NitroFetchOptions<string> = {})
return;
}
console.log("path:", path)
const { revoke, refresh } = useAuth();
const { clearAuth, refresh } = useAuth();
let headers: HeadersInit = {};
@ -61,8 +61,7 @@ export default async <T>(path: string, options: NitroFetchOptions<string> = {})
if (error?.response?.status === 401) {
console.log("Refresh returned 401");
reauthFailed = true;
console.log("Revoking");
await revoke();
await clearAuth()
console.log("Redirecting to login");
await navigateTo("/login");
console.log("redirected");

View file

@ -0,0 +1,11 @@
export default (): "12" | "24" => {
const format = settingsLoad().timeFormat?.format ?? "auto"
if (format == "12") {
return "12"
} else if (format == "24") {
return "24"
}
return "24"
}

View file

@ -0,0 +1,6 @@
export default () => {
const contextMenu = document.getElementById("context-menu");
if (contextMenu) {
contextMenu.remove();
}
}

14
utils/replyToMessage.ts Normal file
View file

@ -0,0 +1,14 @@
import { render } from "vue";
import MessageReply from "~/components/MessageReply.vue";
import type { MessageProps } from "~/types/props";
export default (element: HTMLDivElement, props: MessageProps) => {
console.log("element:", element);
const messageBox = document.getElementById("message-box") as HTMLDivElement;
if (messageBox) {
const div = document.createElement("div");
const messageReply = h(MessageReply, { author: props.author?.display_name || props.author!.username, text: props.text || "", id: props.message.uuid, replyId: props.replyMessage?.uuid || element.dataset.messageId!, maxWidth: "full" });
messageBox.prepend(div);
render(messageReply, div);
}
}

21
utils/settingSave.ts Normal file
View file

@ -0,0 +1,21 @@
export default (key: string, value: any): void => {
let clientSettingsItem: string | null = localStorage.getItem("clientSettings")
if (typeof clientSettingsItem != "string") {
clientSettingsItem = "{}"
}
let clientSettings: { [key: string]: any } = {}
try {
clientSettings = JSON.parse(clientSettingsItem)
} catch {
clientSettings = {}
}
if (typeof clientSettings !== "object") {
clientSettings = {}
}
clientSettings[key] = value
localStorage.setItem("clientSettings", JSON.stringify(clientSettings))
}

21
utils/settingsLoad.ts Normal file
View file

@ -0,0 +1,21 @@
import type { ClientSettings } from "~/types/settings"
export default (): ClientSettings => {
let clientSettingsItem: string | null = localStorage.getItem("clientSettings")
if (typeof clientSettingsItem != "string") {
clientSettingsItem = "{}"
}
let clientSettings: ClientSettings = {}
try {
clientSettings = JSON.parse(clientSettingsItem)
} catch {
clientSettings = {}
}
if (typeof clientSettings !== "object") {
clientSettings = {}
}
return clientSettings
}