refactor: yeet modal, start work on subpage for editing

This commit is contained in:
Calum H. committed 2025-06-14 19:33:04 +01:00
1 parent c48a229900
commit 6482d5b465
6 files changed
+204 -611

No files matched your search

@@ -6,40 +6,40 @@ export class SchedulingModule extends ServerModule {
tasks: ScheduledTask[] = [];
async fetch(): Promise<void> {
this.tasks = await useServersFetch<ScheduledTask[]>(
`servers/${this.serverId}/options/schedules`,
{ version: 1 },
);
// this.tasks = await useServersFetch<ScheduledTask[]>(
// `servers/${this.serverId}/options/schedules`,
// { version: 1 },
// );
}
async deleteTask(task: ScheduledTask): Promise<void> {
await useServersFetch(`servers/${this.serverId}/options/schedules`, {
method: "DELETE",
body: { title: task.title },
version: 1,
});
this.tasks = this.tasks.filter((t) => t.title !== task.title);
// await useServersFetch(`servers/${this.serverId}/options/schedules`, {
// method: "DELETE",
// body: { title: task.title },
// version: 1,
// });
// this.tasks = this.tasks.filter((t) => t.title !== task.title);
}
async createTask(task: ScheduledTask): Promise<number> {
await useServersFetch(`servers/${this.serverId}/options/schedules`, {
method: "POST",
body: task,
version: 1,
});
this.tasks.push(task);
return this.tasks.length;
// await useServersFetch(`servers/${this.serverId}/options/schedules`, {
// method: "POST",
// body: task,
// version: 1,
// });
// this.tasks.push(task);
// return this.tasks.length;
}
async editTask(taskTitle: string, updatedTask: Partial<ScheduledTask>): Promise<void> {
await useServersFetch(`servers/${this.serverId}/options/schedules`, {
method: "PATCH",
body: { title: taskTitle, ...updatedTask },
version: 1,
});
const index = this.tasks.findIndex((t) => t.title === taskTitle);
if (index !== -1) {
this.tasks[index] = { ...this.tasks[index], ...updatedTask };
}
// await useServersFetch(`servers/${this.serverId}/options/schedules`, {
// method: "PATCH",
// body: { title: taskTitle, ...updatedTask },
// version: 1,
// });
// const index = this.tasks.findIndex((t) => t.title === taskTitle);
// if (index !== -1) {
// this.tasks[index] = { ...this.tasks[index], ...updatedTask };
// }
}
}
@@ -6,10 +6,13 @@
<div class="header__row">
<h2 class="header__title text-2xl">Task Scheduling</h2>
<div class="input-group">
<button class="iconified-button brand-button" @click="handleCreateTask">
<NuxtLink
:to="`/servers/manage/${route.params.id}/options/scheduling/new`"
class="iconified-button brand-button"
>
<PlusIcon />
Create Task
</button>
</NuxtLink>
</div>
</div>
@@ -129,9 +132,12 @@
<div>
<div class="flex gap-1">
<ButtonStyled icon-only circular>
<button v-tooltip="'Edit task'" @click="handleTaskEdit(task)">
<NuxtLink
v-tooltip="'Edit task'"
:to="`/servers/manage/${route.params.id}/options/scheduling/${encodeURIComponent(task.title)}`"
>
<EditIcon />
</button>
</NuxtLink>
</ButtonStyled>
<ButtonStyled icon-only circular color="red">
<button
@@ -154,8 +160,6 @@
</section>
</div>
</div>
<ScheduleTaskModal ref="scheduleModal" @save="handleTaskSave" />
</div>
</template>
@@ -172,7 +176,7 @@ import {
SortAscendingIcon as AscendingIcon,
SortDescendingIcon as DescendingIcon,
} from "@modrinth/assets";
import { Toggle, Checkbox, RaisedBadge, ButtonStyled, ScheduleTaskModal } from "@modrinth/ui";
import { Toggle, Checkbox, RaisedBadge, ButtonStyled } from "@modrinth/ui";
import cronstrue from "cronstrue";
import type { ScheduledTask } from "@modrinth/utils";
import { ModrinthServer } from "~/composables/servers/modrinth-servers.ts";
@@ -181,6 +185,8 @@ const props = defineProps<{
server: ModrinthServer;
}>();
const route = useRoute();
onBeforeMount(async () => {
await props.server.scheduling.fetch();
});
@@ -188,7 +194,6 @@ onBeforeMount(async () => {
const selectedTasks = ref<ScheduledTask[]>([]);
const sortBy = ref("Name");
const descending = ref(false);
const scheduleModal = ref();
const tasks = computed(() => props.server.scheduling.tasks);
@@ -238,10 +243,6 @@ async function handleTaskToggle(task: ScheduledTask, enabled: boolean): Promise<
}
}
function handleTaskEdit(task: ScheduledTask): void {
scheduleModal.value?.show(task);
}
async function handleTaskDelete(task: ScheduledTask): Promise<void> {
if (confirm(`Are you sure you want to delete "${task.title}"?`)) {
try {
@@ -254,10 +255,6 @@ async function handleTaskDelete(task: ScheduledTask): Promise<void> {
}
}
function handleCreateTask(): void {
scheduleModal.value?.showNew();
}
async function handleBulkToggle(): Promise<void> {
const enabledCount = selectedTasks.value.filter((t) => t.enabled).length;
const shouldEnable = enabledCount < selectedTasks.value.length / 2;
@@ -288,23 +285,6 @@ async function handleBulkDelete(): Promise<void> {
}
}
async function handleTaskSave(data: ScheduledTask): Promise<void> {
try {
if (scheduleModal.value?.mode === "edit") {
await props.server.scheduling.editTask(
scheduleModal.value.originalData?.title || data.title,
data,
);
console.log("Updated task:", data.title);
} else {
await props.server.scheduling.createTask(data);
console.log("Created task:", data.title);
}
} catch (error) {
console.error("Failed to save task:", error);
}
}
function updateSort(): void {
// Trigger reactivity for sortedTasks
}