Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions website/src/routes/mystuff/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<script lang="ts">
import pb from '$lib/pocketbase';
import { goto } from '$app/navigation';
import CharacterCreateModal from '$lib/components/CharacterCreateModal.svelte';

type ViewMode = 'cps' | 'characters';
let mode = $state<ViewMode>('cps');
let items = $state<any[]>([]);
let isLoading = $state(true);
let deleteModal = $state() as HTMLDialogElement;
let itemToDelete = $state<null | any>(null);
let openCreateCharDialog = $state(false);

const handleDelete = (item: any) => {
itemToDelete = item
deleteModal.showModal()
itemToDelete = item;
deleteModal.showModal();
};

const confirmDelete = async () => {
try {
await pb.collection(itemToDelete.collectionName).delete(itemToDelete.id);
deleteModal.close();
fetchMyData(mode);
} catch (err) {
alert('Delete failed. Please try again.')
console.error('Delete error:', err);
}
}
const confirmDelete = async () => {
try {
await pb.collection(itemToDelete.collectionName).delete(itemToDelete.id);
deleteModal.close();
fetchMyData(mode);
} catch (err) {
alert('Delete failed. Please try again.');
console.error('Delete error:', err);
}
};

async function fetchMyData(currentMode: ViewMode) {
// ๅฎ‰ๅ…จๅฎˆๅซ๏ผšๅฆ‚ๆžœๆฒกๆœ‰็™ปๅฝ•๏ผŒ็›ดๆŽฅ่ทณ่ตฐ
Expand Down Expand Up @@ -88,9 +90,13 @@
You haven't created any {mode === 'cps' ? 'CP' : 'characters'} yet.
</h2>
<div class="mt-4 card-actions">
<a href="/create" class="btn btn-primary"
>Create Your First {mode === 'cps' ? 'CP' : 'character'}</a
>
{#if mode === 'cps'}
<a href="/create" class="btn btn-primary">Create Your First CP</a>
{:else}
<button class="btn btn-primary" onclick={() => (openCreateCharDialog = true)}
>Create Your First Character</button
>
{/if}
</div>
</div>
</div>
Expand Down Expand Up @@ -118,16 +124,16 @@

<dialog bind:this={deleteModal} class="modal">
<div class="modal-box border border-red-200 bg-base-100">
<h3 class="text-base-content text-lg font-bold">Confirm Deletion</h3>
<p class="text-base-content py-4">
<h3 class="text-lg font-bold text-base-content">Confirm Deletion</h3>
<p class="py-4 text-base-content">
Are you sure you want to delete this? This action cannot be undone.
</p>
{#if itemToDelete?.collectionName! == 'cps'}
<p class="text-base-content py-4">
<p class="py-4 text-base-content">
CP cannot be restored after deletion; the character still exists.
</p>
{:else}
<p class="text-base-content py-4">
<p class="py-4 text-base-content">
Once a character is deleted, it cannot be recovered, and the associated CP will also be
deleted.
</p>
Expand All @@ -145,3 +151,4 @@
<button>close</button>
</form>
</dialog>
<CharacterCreateModal bind:open={openCreateCharDialog} afterCreate={() => fetchMyData(mode)} />