Compare commits

..

32 commits

Author SHA1 Message Date
3e4e3e0ce8 Merge pull request 'More improvements to context menu' (#69) from context-menu-ban-kick into main
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
Reviewed-on: #69
Reviewed-by: Twig <git@beaver.mom>
2025-08-16 14:08:33 +00:00
dee08dd152
fix: kick and ban context menu items showing in wrong order due to use of splicing instead of pushing in createMemberContextMenuItems
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
ci/woodpecker/pull_request_closed/build-and-publish Pipeline was successful
2025-08-16 15:52:00 +02:00
8b8c0591a5
feat: add Confirmation modal to MemberEntry.vue
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-16 15:50:11 +02:00
e28bc23d12
fix: Confirmation modal target name not being displayed correctly in Message.vue due to use of display-name prop rather than target-name 2025-08-16 15:49:02 +02:00
839920f124
feat: make custom context menu imitate browser context menu behavior 2025-08-16 15:46:54 +02:00
99ed210d26
fix: sidebar resizing while holding right-click 2025-08-16 15:45:56 +02:00
1d21d476d5
feat: get context menu state variable directly in showContextMenu instead of requiring a context menu object as a parameter 2025-08-16 15:06:44 +02:00
538566e9e1
feat: move initialization of logged-in user member state variable to channelId page 2025-08-16 15:05:07 +02:00
b46533aa5f
fix: change app.vue mousedown listener to pointerdown due to mousedown only listening to left-click, causing context menu not to be removed properly in certain cases 2025-08-16 15:03:58 +02:00
0f02142eb1
feat: replace context menu items splicing with implementation of context menu item sections
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-16 14:25:11 +02:00
c9bbd10af1
feat: rename Confirmation modal prop displayName to targetName 2025-08-16 13:22:21 +02:00
7cb19adfbe
fix: kick and ban would execute regardless of prompt due to calling the function in the Button callback prop instead of just passing it 2025-08-16 12:31:43 +02:00
3a9df965c2
feat: implement Confirmation modal on kick and ban context menu actions
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-16 12:01:36 +02:00
78b7732411
feat: add Confirmation modal to prompt users to confirm or cancel dangerous actions 2025-08-16 11:59:48 +02:00
574ebe8850
fix: CSS merged from main in wrong location
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-15 20:18:51 +02:00
2e8f67133c
fix: missing @contextmenu listeners in Message.vue after merging main
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-15 20:08:00 +02:00
a0baa552e3
fix: member createMemberContextMenuItems using outdated prop 2025-08-15 20:06:31 +02:00
2c30b4e0cd Merge branch 'main' into context-menu-ban-kick 2025-08-15 20:01:28 +02:00
b0d96faa6f
feat: add ability to open member context menu by right-clicking on avatar
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-11 00:10:26 +02:00
f1eda2da75
feat: handle setting of default context menu state variable only in app.vue
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-11 00:04:18 +02:00
ce57b8e7db
feat: remove global context menu event listener and handler to allow regular context menu where a custom one isn't needed 2025-08-11 00:03:47 +02:00
0540f22f5d
feat: move context menu to the left of the cursor if any part of it is beyond the right side of the viewport
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-07 09:01:18 +02:00
51f8c28c54
feat: initialize meMember useState variable on channel load 2025-08-07 09:00:02 +02:00
86af8145b4
feat: make it so opening context menu on an element isn't overridden by another context menu listener on an ancestor of that element 2025-08-07 08:59:20 +02:00
fdfffd78e7
feat: add function to fetch logged-in user's member object for a guild in API composable 2025-08-07 08:58:17 +02:00
0dc485ca77
feat: add functions to kick and ban a member in API composable 2025-08-07 08:57:54 +02:00
e5bdf63f2a
feat: remove context menu on global mousedown only if the context menu useState variable's show value is set to true 2025-08-07 08:57:02 +02:00
46a135de22
feat: add context menu for usernames in members list sidebar 2025-08-07 08:56:07 +02:00
25c5a0e4a8
feat: add context menu for usernames in chat 2025-08-07 08:55:33 +02:00
0d0dccaf84
style(ui): set cursor for usernames in members list sidebar to pointer 2025-08-07 08:54:31 +02:00
dc4494a1db
style(ui): set cursor for usernames in chat to pointer 2025-08-07 08:54:00 +02:00
1bc7877a8b
feat: add util to create context menu items for when right-clicking members in chat or in sidebar 2025-08-07 08:53:11 +02:00
13 changed files with 313 additions and 67 deletions

29
app.vue
View file

@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<Banner v-if="banner" /> <Banner v-if="banner" />
<ContextMenu v-if="contextMenu && contextMenu.show" :pointer-x="contextMenu.pointerX" :pointer-y="contextMenu.pointerY" :menu-items="contextMenu.items" /> <ContextMenu v-if="contextMenu && contextMenu.show" :pointer-x="contextMenu.pointerX" :pointer-y="contextMenu.pointerY" :menu-sections="contextMenu.sections" />
<NuxtPage :keepalive="true" /> <NuxtPage :keepalive="true" />
</div> </div>
</template> </template>
@ -12,22 +12,29 @@ import type { ContextMenuInterface } from './types/interfaces';
const banner = useState("banner", () => false); const banner = useState("banner", () => false);
const contextMenu = useState<ContextMenuInterface>("contextMenu"); const contextMenu = useState<ContextMenuInterface>("contextMenu", () => ({ show: false, pointerX: 0, pointerY: 0, sections: [] }));
onMounted(() => { onMounted(() => {
loadPreferredThemes() loadPreferredThemes()
document.removeEventListener("contextmenu", contextMenuHandler);
document.addEventListener("contextmenu", (e) => { document.addEventListener("contextmenu", (e) => {
if (e.target instanceof Element && e.target.classList.contains("default-contextmenu")) return; if (contextMenu.value.show) {
contextMenuHandler(e); e.preventDefault();
if (e.target instanceof Element && !e.target.classList.contains("context-menu-item")) {
removeContextMenu(contextMenu);
}
}
}); });
document.addEventListener("mousedown", (e) => { document.addEventListener("mousedown", (e) => {
if (e.target instanceof HTMLElement && e.target.closest("#context-menu")) return; if (e.target instanceof HTMLElement && e.target.classList.contains("context-menu-item")) return;
console.log("click"); console.log("click");
console.log("target:", e.target); console.log("target:", e.target);
console.log(e.target instanceof HTMLDivElement); console.log(e.target instanceof HTMLDivElement);
removeContextMenu(contextMenu); if (e.button != 2 && contextMenu.value.show) {
console.log("context menu is shown, hiding");
removeContextMenu(contextMenu);
}
if (e.target instanceof HTMLElement && e.target.classList.contains("message-text") && e.target.contentEditable) { if (e.target instanceof HTMLElement && e.target.classList.contains("message-text") && e.target.contentEditable) {
e.target.contentEditable = "false"; e.target.contentEditable = "false";
} }
@ -52,14 +59,6 @@ onMounted(() => {
}); });
}); });
function contextMenuHandler(e: MouseEvent) {
e.preventDefault();
//console.log("Opened context menu");
//createContextMenu(e, [
// { name: "Wah", callback: () => { return } }
//]);
}
</script> </script>
<style> <style>

View file

@ -1,17 +1,20 @@
<template> <template>
<div class="member-item" @click.prevent="showModalPopup" tabindex="0"> <div class="member-item" @click.prevent="showModalPopup" tabindex="0" @contextmenu="showContextMenu($event, menuSections)">
<Avatar :profile="props.member" class="member-avatar"/> <Avatar :profile="props.member" class="member-avatar"/>
<span class="member-display-name" :style="`color: ${generateIrcColor(props.member.user.uuid)}`"> <span class="member-display-name" :style="`color: ${generateIrcColor(props.member.user.uuid)}`">
{{ getDisplayName(props.member) }} {{ getDisplayName(props.member) }}
</span> </span>
</div> </div>
<ModalProfilePopup v-if="modalPopupVisible" :profile="props.member" <ModalProfilePopup v-if="modalPopupVisible" :profile="props.member"
:onFinish="hideModalPopup" :keepalive="false"/> :onFinish="hideModalPopup" :keepalive="false" />
<ModalConfirmation v-if="confirmationModal && confirmationModal.show" :action-name="confirmationModal.actionName"
:target-name="getDisplayName(props.member)" :callback="confirmationModal.callback"
:onClose="resetConfirmationModal" :onCancel="resetConfirmationModal" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ModalProfilePopup } from '#components'; import { ModalProfilePopup } from '#components';
import type { GuildMemberResponse } from '~/types/interfaces'; import type { GuildMemberResponse, IConfirmationModal } from '~/types/interfaces';
const { getDisplayName } = useProfile() const { getDisplayName } = useProfile()
@ -19,8 +22,12 @@ const props = defineProps<{
member: GuildMemberResponse member: GuildMemberResponse
}>(); }>();
const confirmationModal = ref<IConfirmationModal>();
const menuSections = await createMemberContextMenuItems(props.member, props.member.guild_uuid, confirmationModal);
const modalPopupVisible = ref<boolean>(false); const modalPopupVisible = ref<boolean>(false);
function showModalPopup() { function showModalPopup() {
modalPopupVisible.value = true modalPopupVisible.value = true
} }
@ -28,9 +35,18 @@ function showModalPopup() {
function hideModalPopup() { function hideModalPopup() {
modalPopupVisible.value = false modalPopupVisible.value = false
} }
function resetConfirmationModal() {
console.log("[CONFIRM] resetting");
if (confirmationModal) {
confirmationModal.value = { show: false, actionName: "", callback: () => {} };
}
}
</script> </script>
<style> <style>
.member-item { .member-item {
display: flex; display: flex;
margin-top: .5em; margin-top: .5em;
@ -49,6 +65,7 @@ function hideModalPopup() {
} }
.member-display-name { .member-display-name {
cursor: pointer;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }

View file

@ -1,5 +1,5 @@
<template> <template>
<div v-if="props.type == 'normal' || props.replyMessage" ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, menuItems)" <div v-if="props.type == 'normal' || props.replyMessage" ref="messageElement" @contextmenu="showContextMenu($event, messageMenuSections)"
class="message normal-message" :class="{ 'highlighted': (props.isMentioned || (props.replyMessage && props.message.member.user.uuid != me!.uuid && props.replyMessage?.member.user.uuid == me!.uuid)) }" class="message normal-message" :class="{ 'highlighted': (props.isMentioned || (props.replyMessage && props.message.member.user.uuid != me!.uuid && props.replyMessage?.member.user.uuid == me!.uuid)) }"
:data-message-id="props.message.uuid" :editing.sync="props.editing"> :data-message-id="props.message.uuid" :editing.sync="props.editing">
<div v-if="props.replyMessage" class="message-reply-svg"> <div v-if="props.replyMessage" class="message-reply-svg">
@ -27,11 +27,12 @@
:text="props.replyMessage?.message" :text="props.replyMessage?.message"
:reply-id="props.replyMessage.uuid" max-width="reply" /> :reply-id="props.replyMessage.uuid" max-width="reply" />
<div class="left-column"> <div class="left-column">
<Avatar :profile="props.message.member" class="message-author-avatar"/> <Avatar :profile="props.message.member" class="message-author-avatar" @contextmenu="showContextMenu($event, memberMenuSections)" />
</div> </div>
<div class="message-data"> <div class="message-data">
<div class="message-metadata"> <div class="message-metadata">
<span class="message-author-username" tabindex="0" :style="`color: ${generateIrcColor(props.message.member.user.uuid)}`"> <span class="message-author-username" tabindex="0" :style="`color: ${generateIrcColor(props.message.member.user.uuid)}`"
@contextmenu="showContextMenu($event, memberMenuSections)">
{{ getDisplayName(props.message.member) }} {{ getDisplayName(props.message.member) }}
</span> </span>
<span class="message-date" :title="date.toString()"> <span class="message-date" :title="date.toString()">
@ -45,7 +46,7 @@
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks" /> <MessageMedia v-if="mediaLinks.length" :links="mediaLinks" />
</div> </div>
</div> </div>
<div v-else ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, menuItems)" <div v-else ref="messageElement" @contextmenu="showContextMenu($event, messageMenuSections)"
class="message grouped-message" :class="{ 'mentioned': props.replyMessage || props.isMentioned }" class="message grouped-message" :class="{ 'mentioned': props.replyMessage || props.isMentioned }"
:data-message-id="props.message.uuid" :editing.sync="props.editing"> :data-message-id="props.message.uuid" :editing.sync="props.editing">
<div class="left-column"> <div class="left-column">
@ -58,6 +59,9 @@
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks"/> <MessageMedia v-if="mediaLinks.length" :links="mediaLinks"/>
</div> </div>
</div> </div>
<ModalConfirmation v-if="confirmationModal && confirmationModal.show" :action-name="confirmationModal.actionName"
:target-name="getDisplayName(props.message.member)" :callback="confirmationModal.callback"
:onClose="resetConfirmationModal" :onCancel="resetConfirmationModal" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -66,17 +70,17 @@ import { parse } from 'marked';
import type { MessageProps } from '~/types/props'; import type { MessageProps } from '~/types/props';
import MessageMedia from './MessageMedia.vue'; import MessageMedia from './MessageMedia.vue';
import MessageReply from './UserInterface/MessageReply.vue'; import MessageReply from './UserInterface/MessageReply.vue';
import type { ContextMenuInterface, ContextMenuItem } from '~/types/interfaces'; import type { ContextMenuSection, IConfirmationModal } from '~/types/interfaces';
const { getDisplayName } = useProfile() const { getDisplayName } = useProfile()
const { getUser } = useAuth() const { getUser } = useAuth()
const route = useRoute();
const props = defineProps<MessageProps>(); const props = defineProps<MessageProps>();
const me = await getUser() const me = await getUser()
const contextMenu = useState<ContextMenuInterface>("contextMenu", () => ({ show: false, pointerX: 0, pointerY: 0, items: [] }));
const messageElement = ref<HTMLDivElement>(); const messageElement = ref<HTMLDivElement>();
const dateHidden = ref<boolean>(true); const dateHidden = ref<boolean>(true);
@ -85,6 +89,10 @@ const date = uuidToDate(props.message.uuid);
const currentDate: Date = new Date() const currentDate: Date = new Date()
const confirmationModal = ref<IConfirmationModal>();
const memberMenuSections = ref<ContextMenuSection[]>([]);
console.log("[MSG] message to render:", props.message); console.log("[MSG] message to render:", props.message);
console.log("author:", props.message.member); console.log("author:", props.message.member);
console.log("[MSG] reply message:", props.replyMessage); console.log("[MSG] reply message:", props.replyMessage);
@ -152,25 +160,39 @@ onMounted(async () => {
}; };
console.log("media links:", mediaLinks); console.log("media links:", mediaLinks);
console.log("[CONFIRM] modal:", confirmationModal.value);
memberMenuSections.value = await createMemberContextMenuItems(props.message.member, route.params.serverId as string, confirmationModal);
}); });
//function toggleTooltip(e: Event) { //function toggleTooltip(e: Event) {
// showHover.value = !showHover.value; // showHover.value = !showHover.value;
//} //}
const menuItems: ContextMenuItem[] = [ const messageMenuSections: ContextMenuSection[] = [];
{ name: "Reply", icon: "lucide:reply", type: "normal", callback: () => { if (messageElement.value) replyToMessage(messageElement.value, props) } }
] const regularSection: ContextMenuSection = {
items: [
{
name: "Reply",
icon: "lucide:reply",
type: "normal",
callback: () => { if (messageElement.value) replyToMessage(messageElement.value, props)}
}
]
};
console.log("me:", me); console.log("me:", me);
if (props.message.member.user.uuid == me!.uuid) { if (props.message.member.user.uuid == me!.uuid) {
// Inserts "edit" option at index 1 (below the "reply" option) regularSection.items.push({ name: "Edit (WIP)", icon: "lucide:square-pen", type: "normal", callback: () => { /* if (messageElement.value) editMessage(messageElement.value, props) */ } });
menuItems.splice(1, 0, { name: "Edit (WIP)", icon: "lucide:square-pen", type: "normal", callback: () => { /* if (messageElement.value) editMessage(messageElement.value, props) */ } });
} }
if (props.message.member.user.uuid == me!.uuid /* || check message delete permission*/) { if (props.message.member.user.uuid == me!.uuid) {
// Inserts "edit" option at index 2 (below the "edit" option) regularSection.items.push({ name: "Delete (WIP)", icon: "lucide:trash", type: "danger", callback: () => {} });
menuItems.splice(2, 0, { name: "Delete (WIP)", icon: "lucide:trash", type: "danger", callback: () => {} }); }
if (regularSection.items.length) {
messageMenuSections.push(regularSection);
} }
function getDayDifference(date1: Date, date2: Date) { function getDayDifference(date1: Date, date2: Date) {
@ -184,6 +206,13 @@ function getDayDifference(date1: Date, date2: Date) {
return Math.round(dayDifference); return Math.round(dayDifference);
} }
function resetConfirmationModal() {
console.log("[CONFIRM] resetting");
if (confirmationModal) {
confirmationModal.value = { show: false, actionName: "", callback: () => {} };
}
}
</script> </script>
<style scoped> <style scoped>
@ -243,6 +272,11 @@ function getDayDifference(date1: Date, date2: Date) {
max-height: 2.5em; max-height: 2.5em;
min-width: 2.5em; min-width: 2.5em;
max-width: 2.5em; max-width: 2.5em;
cursor: pointer;
}
.message-author-username {
cursor: pointer;
} }
.left-column { .left-column {

View file

@ -25,6 +25,11 @@ onMounted(() => {
if (props.onCancel) dialog.value.addEventListener("cancel", props.onCancel); if (props.onCancel) dialog.value.addEventListener("cancel", props.onCancel);
} }
}); });
function close() { dialog.value?.close() }
defineExpose({ close });
</script> </script>
<style scoped> <style scoped>

View file

@ -0,0 +1,54 @@
<template>
<ModalBase ref="modal" class="confirmation-modal" :obscure="true" :onClose="props.onClose" :onCancel="props.onCancel">
<div class="confirmation-modal-body">
<div>
<h1 class="confirmation-modal-message">Are you sure you would like to {{ props.actionName.toLowerCase() }} {{ props.targetName }}?</h1>
</div>
<div class="confirmation-modal-buttons">
<Button :variant="'normal'" :text="'Cancel'" @click="closeModal()" />
<Button :variant="'scary'" :text="'Confirm'" :callback="props.callback" />
</div>
</div>
</ModalBase>
</template>
<script lang="ts" setup>
import Button from '../UserInterface/Button.vue';
const props = defineProps<{ actionName: string, targetName?: string, callback: CallableFunction, onClose: () => void, onCancel: () => void }>();
const modal = ref<{ close: () => void }>();
function closeModal() {
const test = document.getElementsByClassName("confirmation-modal")[0];
console.log("[CONFIRM] modal rah:", test);
if (modal.value) {
modal.value.close();
}
}
</script>
<style>
.confirmation-modal-body {
display: flex;
flex-direction: column;
background-color: var(--modal-background-color);
align-items: center;
text-align: center;
padding: 1rem;
color: var(--text-color);
border: .1rem solid var(--primary-color);
}
.confirmation-modal-buttons {
display: flex;
gap: 1rem;
}
.confirmation-modal-message {
font-size: 1.5em;
}
</style>

View file

@ -1,23 +1,33 @@
<template> <template>
<div id="context-menu"> <div id="context-menu">
<button v-for="item of props.menuItems" class="context-menu-item" <template v-for="(section, index) of props.menuSections">
:class="'context-menu-item-' + item.type" <div class="context-menu-section">
@click="runCallback(item)"> <button v-for="item of section.items" class="context-menu-item"
{{ item.name }} <Icon v-if="item.icon" :name="item.icon" /> :class="'context-menu-item-' + item.type"
</button> @click="runCallback(item)">
{{ item.name }} <Icon v-if="item.icon" :name="item.icon" />
</button>
</div>
<VerticalSpacer v-if="index < props.menuSections.length - 1" class="context-menu-section-spacer" />
</template>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { ContextMenuInterface, ContextMenuItem } from '~/types/interfaces'; import type { ContextMenuInterface, ContextMenuItem, ContextMenuSection } from '~/types/interfaces';
import VerticalSpacer from './VerticalSpacer.vue';
const props = defineProps<{ menuItems: ContextMenuItem[], pointerX: number, pointerY: number }>(); const props = defineProps<{ menuSections: ContextMenuSection[], pointerX: number, pointerY: number }>();
onMounted(() => { onMounted(() => {
const contextMenu = document.getElementById("context-menu"); const contextMenu = document.getElementById("context-menu");
if (contextMenu) { if (contextMenu) {
contextMenu.style.left = props.pointerX.toString() + "px"; contextMenu.style.left = props.pointerX.toString() + "px";
contextMenu.style.top = props.pointerY.toString() + "px"; contextMenu.style.top = props.pointerY.toString() + "px";
const rect = contextMenu.getBoundingClientRect();
if (rect.right > (window.innerWidth || document.documentElement.clientWidth)) {
contextMenu.style.left = (props.pointerX - contextMenu.clientWidth).toString() + "px";
}
} }
}); });
@ -38,7 +48,7 @@ function runCallback(item: ContextMenuItem) {
flex-direction: column; flex-direction: column;
width: 10rem; width: 10rem;
border: .1rem solid var(--reply-text-color); border: .1rem solid var(--reply-text-color);
background-color: var(--sidebar-highlighted-background-color); background-color: var(--popup-background-color);
text-align: left; text-align: left;
z-index: 100; z-index: 100;
} }
@ -65,4 +75,8 @@ function runCallback(item: ContextMenuItem) {
color: var(--danger-text-color); color: var(--danger-text-color);
} }
.context-menu-section-spacer {
margin: 0 !important;
}
</style> </style>

View file

@ -8,20 +8,22 @@
'border-top': props.borderSides?.includes('top') ? borderStyling : undefined, 'border-top': props.borderSides?.includes('top') ? borderStyling : undefined,
'border-bottom': props.borderSides?.includes('bottom') ? borderStyling : undefined, 'border-bottom': props.borderSides?.includes('bottom') ? borderStyling : undefined,
}"> }">
<div v-if="props.borderSides != 'right'" class="width-resizer-bar"> <div v-if="props.borderSides != 'right'" class="width-resizer-bar"
@contextmenu="showContextMenu($event, menuSections)">
<div ref="widthResizer" class="width-resizer"></div> <div ref="widthResizer" class="width-resizer"></div>
</div> </div>
<div class="sidebar-content"> <div class="sidebar-content">
<slot /> <slot />
</div> </div>
<div v-if="props.borderSides == 'right'" class="width-resizer-bar"> <div v-if="props.borderSides == 'right'" class="width-resizer-bar"
@contextmenu="showContextMenu($event, menuSections)">
<div ref="widthResizer" class="width-resizer"></div> <div ref="widthResizer" class="width-resizer"></div>
</div> </div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { ContextMenuInterface, ContextMenuItem } from '~/types/interfaces'; import type { ContextMenuInterface, ContextMenuItem, ContextMenuSection } from '~/types/interfaces';
const props = defineProps<{ width?: string, minWidth: string, maxWidth: string, borderSides: "all" | "top" | "right" | "bottom" | "left" | ("top" | "right" | "bottom" | "left")[], localStorageName?: string }>(); const props = defineProps<{ width?: string, minWidth: string, maxWidth: string, borderSides: "all" | "top" | "right" | "bottom" | "left" | ("top" | "right" | "bottom" | "left")[], localStorageName?: string }>();
@ -31,16 +33,19 @@ const resizableSidebar = ref<HTMLDivElement>();
const widthResizer = ref<HTMLDivElement>(); const widthResizer = ref<HTMLDivElement>();
const storedWidth = ref<string>(); const storedWidth = ref<string>();
const contextMenu = useState<ContextMenuInterface>("contextMenu"); const menuSections: ContextMenuSection[] = [{
items: [
const menuItems: ContextMenuItem[] = [ {
{ name: "Reset", type: "normal", callback: () => { name: "Reset", type: "normal", callback: () => {
const defaultWidth = props.width ?? props.minWidth; const defaultWidth = props.width ?? props.minWidth;
resizableSidebar.value!.style.width = defaultWidth; resizableSidebar.value!.style.width = defaultWidth;
if (props.localStorageName) { if (props.localStorageName) {
localStorage.setItem(props.localStorageName, defaultWidth); localStorage.setItem(props.localStorageName, defaultWidth);
}
}
} }
} } ]
}
] ]
onMounted(() => { onMounted(() => {
@ -48,11 +53,8 @@ onMounted(() => {
if (resizableSidebar.value && widthResizer.value) { if (resizableSidebar.value && widthResizer.value) {
widthResizer.value.addEventListener("pointerdown", (e) => { widthResizer.value.addEventListener("pointerdown", (e) => {
if (e.button != 0) return;
e.preventDefault(); e.preventDefault();
if (e.button == 2) {
showContextMenu(e, contextMenu.value, menuItems);
return
};
document.body.style.cursor = "ew-resize"; document.body.style.cursor = "ew-resize";
function handleMove(pointer: PointerEvent) { function handleMove(pointer: PointerEvent) {
if (resizableSidebar.value) { if (resizableSidebar.value) {

View file

@ -25,6 +25,17 @@ export const useApi = () => {
return await fetchWithApi("/me") return await fetchWithApi("/me")
} }
async function fetchMeMember(guildId: string): Promise<GuildMemberResponse | undefined> {
const { getUser } = useAuth();
const me = await getUser();
if (me) {
const members = await fetchMembers(guildId);
const meMember = members.objects.find(member => member.user.uuid == me.uuid);
return meMember;
}
}
async function fetchChannels(guildId: string): Promise<ChannelResponse[]> { async function fetchChannels(guildId: string): Promise<ChannelResponse[]> {
return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/channels`)); return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/channels`));
} }
@ -47,6 +58,14 @@ export const useApi = () => {
async function fetchMember(guildId: string, memberId: string): Promise<GuildMemberResponse | undefined> { async function fetchMember(guildId: string, memberId: string): Promise<GuildMemberResponse | undefined> {
return await fetchWithApi(`/guilds/${guildId}/members/${memberId}`); return await fetchWithApi(`/guilds/${guildId}/members/${memberId}`);
} }
async function kickMember(memberId: string) {
return await fetchWithApi(`/members/${memberId}`, { method: "DELETE" });
}
async function banMember(guildId: string, memberId: string) {
//
}
async function fetchUsers() { async function fetchUsers() {
return await fetchWithApi(`/users`); return await fetchWithApi(`/users`);
@ -114,10 +133,13 @@ export const useApi = () => {
fetchGuild, fetchGuild,
fetchMyGuilds, fetchMyGuilds,
fetchMe, fetchMe,
fetchMeMember,
fetchChannels, fetchChannels,
fetchChannel, fetchChannel,
fetchMembers, fetchMembers,
fetchMember, fetchMember,
kickMember,
banMember,
fetchUsers, fetchUsers,
fetchUser, fetchUser,
fetchFriends, fetchFriends,

View file

@ -16,6 +16,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { GuildMemberResponse } from '~/types/interfaces';
const route = useRoute(); const route = useRoute();
const { fetchGuild, fetchChannel } = useApi() const { fetchGuild, fetchChannel } = useApi()
@ -28,6 +30,13 @@ const channelUrlPath = `channels/${channelId}`;
const guild = await fetchGuild(guildId) const guild = await fetchGuild(guildId)
const channel = await fetchChannel(channelId) const channel = await fetchChannel(channelId)
const { fetchMeMember } = useApi();
const me = useState<GuildMemberResponse | undefined>("me");
if (!me.value || me.value.guild_uuid != guildId) {
const fetchedMe = await fetchMeMember(guildId);
me.value = fetchedMe;
}
// function toggleInvitePopup(e: Event) { // function toggleInvitePopup(e: Event) {
// e.preventDefault(); // e.preventDefault();
// showInvitePopup.value = !showInvitePopup.value; // showInvitePopup.value = !showInvitePopup.value;

View file

@ -115,11 +115,16 @@ export interface ContextMenuItem {
callback: (...args: any[]) => any; callback: (...args: any[]) => any;
} }
export interface ContextMenuSection {
name?: string
items: ContextMenuItem[]
}
export interface ContextMenuInterface { export interface ContextMenuInterface {
show: boolean, show: boolean,
pointerX: number, pointerX: number,
pointerY: number, pointerY: number,
items: ContextMenuItem[] sections: ContextMenuSection[]
} }
export interface NavbarItem { export interface NavbarItem {
@ -140,3 +145,8 @@ export interface NavbarOptions {
isDirectMessages?: boolean isDirectMessages?: boolean
} }
export interface IConfirmationModal {
show: boolean,
actionName: string,
callback: CallableFunction
}

View file

@ -0,0 +1,70 @@
import { Permission } from "~/types/enums";
import type { ContextMenuSection, GuildMemberResponse, IConfirmationModal } from "~/types/interfaces";
export default async (member: GuildMemberResponse, guildId: string, confirmationModal?: Ref<IConfirmationModal | undefined>) => {
const menuSections: ContextMenuSection[] = [];
const moderationSection: ContextMenuSection = {
name: "Moderation",
items: []
};
const me = useState<GuildMemberResponse | undefined>("me");
const { banMember, kickMember } = useApi();
console.log("[MENUITEM] hi");
console.log("[MENUITEM] member:", member.user.username);
console.log("[MENUITEM] me:", me.value?.user.username);
if (me.value && member.uuid != me.value.uuid) {
console.log("[MENUITEM] member is not me");
if (hasPermission(me.value, Permission.KickMember)) {
console.log("[MENUITEM] has kick member permission");
moderationSection.items.push({
name: "Kick",
icon: "lucide:user-x",
type: "danger",
callback: async () => {
if (confirmationModal) {
console.log("[CONFIRM] HEYO THERE!!");
confirmationModal.value = {
actionName: "kick",
callback: async () => await kickMember(member.uuid),
show: true
}
} else {
console.log("[CONFIRM] no modal");
await kickMember(member.uuid)
}
}
});
}
if (hasPermission(me.value, Permission.BanMember)) {
console.log("[MENUITEM] has ban permission");
moderationSection.items.push({
name: "Ban (WIP)",
icon: "lucide:ban",
type: "danger",
callback: async () => {
if (confirmationModal) {
console.log("[CONFIRM] HEYO THERE!! 2");
confirmationModal.value = {
actionName: "ban",
callback: async () => await banMember(member.guild_uuid, member.uuid),
show: true
}
} else {
console.log("[CONFIRM] no modal 2");
await banMember(member.guild_uuid, member.uuid)
}
}
});
}
}
if (moderationSection.items.length) {
menuSections.push(moderationSection);
}
console.log("[MENUITEM] returning menu items:", menuSections);
return menuSections;
}

View file

@ -6,7 +6,7 @@ export default (contextMenu: Ref<ContextMenuInterface>) => {
show: false, show: false,
pointerX: 0, pointerX: 0,
pointerY: 0, pointerY: 0,
items: [] sections: []
} }
console.log("hidden context menu"); console.log("hidden context menu");
} }

View file

@ -1,12 +1,22 @@
import { render } from "vue"; import { render } from "vue";
import ContextMenu from "~/components/UserInterface/ContextMenu.vue"; import ContextMenu from "~/components/UserInterface/ContextMenu.vue";
import type { ContextMenuInterface, ContextMenuItem } from "~/types/interfaces"; import type { ContextMenuInterface, ContextMenuItem, ContextMenuSection } from "~/types/interfaces";
export default (e: MouseEvent | PointerEvent, contextMenu: ContextMenuInterface, menuItems: ContextMenuItem[]) => { export default (e: MouseEvent | PointerEvent, sections: ContextMenuSection[]) => {
console.log("Showing context menu"); e.preventDefault();
contextMenu.show = true; e.stopPropagation();
contextMenu.pointerX = e.clientX; const contextMenu = useState<ContextMenuInterface>("contextMenu");
contextMenu.pointerY = e.clientY; if (contextMenu.value.show) {
contextMenu.items = menuItems; removeContextMenu(contextMenu);
console.log("Showed"); } else {
console.log("Menu sections:", sections);
if (sections.length) {
console.log("Showing context menu");
contextMenu.value.show = true;
contextMenu.value.pointerX = e.clientX;
contextMenu.value.pointerY = e.clientY;
contextMenu.value.sections = sections;
console.log("Showed");
}
}
} }