-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/my stuff #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/my stuff #26
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,90 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <script lang="ts"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pb from '$lib/pocketbase'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { goto } from '$app/navigation'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type ViewMode = 'cps' | 'characters'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mode = $state<ViewMode>('cps'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let items = $state<any[]>([]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let isLoading = $state(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function fetchMyData(currentMode: ViewMode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 安全守卫:如果没有登录,直接跳走 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!pb.authStore.isValid || !pb.authStore.record) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| goto('/login'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
BretRen marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isLoading = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const userId = pb.authStore.record.id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const collection = currentMode === 'cps' ? 'cps' : 'characters'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const options = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 关键点:只获取 owner 是当前用户的记录 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filter: `owner = "${userId}"`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
BretRen marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sort: '-created', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expand: currentMode === 'cps' ? 'characters' : '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| items = await pb.collection(collection).getFullList(options); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Fetch error:", err); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isLoading = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against stale responses when switching tabs. Line 39 can start overlapping requests; a slower previous response can still assign 🐛 Proposed fix to ignore stale loads let mode = $state<ViewMode>('cps');
let items = $state<any[]>([]);
let isLoading = $state(true);
+ let fetchVersion = 0;
async function fetchMyData(currentMode: ViewMode) {
+ const version = ++fetchVersion;
+
// 安全守卫:如果没有登录,直接跳走
if (!pb.authStore.isValid || !pb.authStore.record) {
- goto('/login');
+ isLoading = false;
+ await goto('/login');
return;
}
isLoading = true;
const userId = pb.authStore.record.id;
@@
- items = await pb.collection(collection).getFullList(options);
+ const nextItems = await pb.collection(collection).getFullList(options);
+ if (version === fetchVersion) {
+ items = nextItems;
+ }
} catch (err) {
console.error("Fetch error:", err);
+ if (version === fetchVersion) {
+ items = [];
+ }
} finally {
- isLoading = false;
+ if (version === fetchVersion) {
+ isLoading = false;
+ }
}
}Also applies to: 37-40 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 监听 mode 变化自动刷新 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $effect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fetchMyData(mode); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </script> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="mx-auto max-w-6xl px-6 py-16"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="mb-12"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <h1 class="text-4xl font-bold md:text-5xl">My Stuff</h1> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <p class="text-base-content/60 mt-2">Manage the CPs and Characters you've created.</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div role="tablist" class="tabs tabs-boxed mt-6 w-fit"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| role="tab" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="tab {mode === 'cps' ? 'tab-active' : ''}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onclick={() => mode = 'cps'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| >My CPs</button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| role="tab" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="tab {mode === 'characters' ? 'tab-active' : ''}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onclick={() => mode = 'characters'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| >My Characters</button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expose the active tab state to assistive technology. These buttons declare ♿ Proposed tab accessibility fix <button
+ type="button"
role="tab"
+ aria-selected={mode === 'cps'}
class="tab {mode === 'cps' ? 'tab-active' : ''}"
onclick={() => mode = 'cps'}
>My CPs</button>
<button
+ type="button"
role="tab"
+ aria-selected={mode === 'characters'}
class="tab {mode === 'characters' ? 'tab-active' : ''}"
onclick={() => mode = 'characters'}
>My Characters</button>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {#if isLoading} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="flex justify-center py-20"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span class="loading loading-spinner loading-lg text-primary"></span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {:else if items.length === 0} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="card bg-base-200 py-20 text-center border-2 border-dashed border-base-300"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="card-body items-center"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <h2 class="card-title text-2xl opacity-40">You haven't created any {mode} yet.</h2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="card-actions mt-4"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <a href="/create" class="btn btn-primary">Create Your First {mode === 'cps' ? 'CP' : 'Char'}</a> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {:else} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {#each items as item} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="card bg-base-100 shadow-xl border border-base-200"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="card-body p-5"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <h2 class="card-title">{item.name}</h2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="card-actions justify-end mt-4"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <a href="/edit/{mode}/{item.id}" class="btn btn-sm btn-ghost">Edit</a> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Verify that SvelteKit route files exist for the edit URLs generated by My Stuff.
# Expected: route files/directories matching /edit/cps/[id] and /edit/characters/[id], or update the hrefs to the actual edit route shape.
printf 'Generated edit hrefs in Svelte files:\n'
rg -nP 'href="/edit/\{mode\}/\{item\.id\}"' -C2 --glob '*.svelte' || true
printf '\nRelevant SvelteKit route files:\n'
fd -p '\+page\.svelte$' website/src/routes \
| sort \
| rg '/edit/|/cps/|/characters/' || trueRepository: pdnode-team/cp Length of output: 790 🏁 Script executed: #!/bin/bash
# Check if /edit directory exists and list all route files
printf 'Checking for /edit directory:\n'
ls -la website/src/routes/ | grep edit || echo "No /edit directory found"
printf '\nAll +page.svelte files in website/src/routes:\n'
find website/src/routes -name '+page.svelte' -type f | sort
printf '\nChecking for any edit route patterns:\n'
find website/src/routes -type d -name edit || echo "No /edit directory found"Repository: pdnode-team/cp Length of output: 555 🏁 Script executed: #!/bin/bash
# Search for any edit route references or edit functionality
printf 'Searching for edit-related functionality:\n'
rg -i 'edit.*route|route.*edit' website/src/routes --type svelte -l || echo "No edit route references found"
printf '\nSearching for +layout or server files that might handle edit:\n'
find website/src/routes/edit website/src/routes/cps website/src/routes/characters -name '+layout*' -o -name '+server*' 2>/dev/null || echo "No edit layout/server files found"
printf '\nChecking mystuff page for edit functionality context:\n'
grep -n -i 'edit' website/src/routes/mystuff/+page.svelteRepository: pdnode-team/cp Length of output: 432 Update the Edit link destination or create the edit routes. The edit routes at 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <a href="/{mode}/{item.id}" class="btn btn-sm btn-primary">View</a> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/each} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/if} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.