feat: add utils to reply to and edit messages
This commit is contained in:
parent
b51efc01e9
commit
b28920898c
3 changed files with 46 additions and 0 deletions
17
types/props.ts
Normal file
17
types/props.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import type { UserResponse } from "./interfaces";
|
||||
|
||||
export interface MessageProps {
|
||||
class?: string,
|
||||
img?: string | null,
|
||||
author?: UserResponse
|
||||
text: string,
|
||||
timestamp: number,
|
||||
format: "12" | "24",
|
||||
type: "normal" | "grouped",
|
||||
marginBottom: boolean,
|
||||
last: boolean,
|
||||
messageId: string,
|
||||
replyingTo?: boolean,
|
||||
editing?: boolean,
|
||||
me: UserResponse
|
||||
}
|
24
utils/editMessage.ts
Normal file
24
utils/editMessage.ts
Normal 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 });
|
||||
}
|
||||
}
|
5
utils/replyToMessage.ts
Normal file
5
utils/replyToMessage.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import type { MessageProps } from "~/types/props";
|
||||
|
||||
export default (element: HTMLDivElement, props: MessageProps) => {
|
||||
console.log("element:", element);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue