Skip to content

Commit

Permalink
Change action signature context-menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruptein committed Dec 29, 2024
1 parent ef815ba commit 5dc2cdd
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 78 deletions.
18 changes: 9 additions & 9 deletions client/src/assets/ui/AssetContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ const canShare = computed(() => {
return data.owner === username || data.shares.some((s) => s.user === username && s.right === "edit");
});
function rename(): void {
if (multiSelect.value) return;
function rename(): boolean {
if (multiSelect.value) return true;
const asset = assetState.raw.idMap.get(assetState.raw.selected[0]!);
if (asset === undefined) {
console.error("Attempt to rename unknown file");
return close();
return true;
}
emit("rename", asset.id);
close();
return true;
}
function share(): void {
function share(): boolean {
showAssetShare.value = true;
close();
return true;
}
async function remove(): Promise<void> {
if (assetState.raw.selected.length === 0) return;
async function remove(): Promise<boolean> {
if (assetState.raw.selected.length === 0) return false;
const result = await modals.confirm(t("assetManager.AssetContextMenu.ask_remove"));
if (result === true) {
assetSystem.removeSelection();
}
close();
return true;
}
const sections = computed<Section[]>(() => [
Expand Down
2 changes: 1 addition & 1 deletion client/src/core/components/contextMenu/ContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const visibleSections = computed(() => props.sections.filter((section) => isVisi
@contextmenu.stop.prevent
>
<ul>
<ContextMenuSection :sections="visibleSections" />
<ContextMenuSection :sections="visibleSections" @cm:close="$emit('cm:close')" />
</ul>
</div>
</template>
Expand Down
10 changes: 9 additions & 1 deletion client/src/core/components/contextMenu/ContextMenuSection.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<script setup lang="ts">
import type { Section } from "./types";
const emit = defineEmits<(e: "cm:close") => void>();
defineProps<{ sections: Section[]; addDivider?: boolean }>();
async function doAction(action: () => boolean | Promise<boolean>): Promise<void> {
const result = await action();
if (result) {
emit("cm:close");
}
}
</script>

<template>
Expand All @@ -19,7 +27,7 @@ defineProps<{ sections: Section[]; addDivider?: boolean }>();
</li>
</template>
<template v-else>
<li :class="{ selected: section.selected }" @click="section.action()">
<li :class="{ selected: section.selected }" @click="doAction(section.action)">
<span>{{ section.title }}</span>
</li>
</template>
Expand Down
2 changes: 1 addition & 1 deletion client/src/core/components/contextMenu/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface BaseSection {
title: string;
action: () => void | Promise<void>;
action: () => boolean | Promise<boolean>;
disabled?: boolean;
selected?: boolean;
}
Expand Down
21 changes: 11 additions & 10 deletions client/src/game/ui/contextmenu/DefaultContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ function close(): void {
showDefaultContextMenu.value = false;
}
function bringPlayers(): void {
if (!gameState.raw.isDm) return;
function bringPlayers(): boolean {
if (!gameState.raw.isDm) return false;
sendBringPlayers({
floor: floorState.currentFloor.value!.name,
x: l2gx(defaultContextLeft.value),
y: l2gy(defaultContextTop.value),
});
close();
return true;
}
async function createSpawnLocation(): Promise<void> {
if (!gameState.raw.isDm) return;
async function createSpawnLocation(): Promise<boolean> {
if (!gameState.raw.isDm) return false;
const spawnLocations = locationSettingsState.raw.spawnLocations.value;
const spawnName = await modals.prompt(
Expand All @@ -61,7 +61,7 @@ async function createSpawnLocation(): Promise<void> {
return { valid: true };
},
);
if (spawnName === undefined || spawnName === "") return;
if (spawnName === undefined || spawnName === "") return false;
const uuid = uuidv4();
const src = "/static/img/spawn.png";
Expand All @@ -87,16 +87,17 @@ async function createSpawnLocation(): Promise<void> {
locationSettingsState.raw.activeLocation,
true,
);
return true;
}
function showInitiativeDialog(): void {
function showInitiativeDialog(): boolean {
initiativeStore.show(true, true);
close();
return true;
}
function showTokenDialog(): void {
function showTokenDialog(): boolean {
openCreateTokenDialog({ x: defaultContextLeft.value, y: defaultContextTop.value });
close();
return true;
}
const sections = computed<Section[]>(() => {
Expand Down
Loading

0 comments on commit 5dc2cdd

Please sign in to comment.