Skip to content

Commit a7a4d49

Browse files
committed
support url param handling (https://t3.0xgingi.xyz/chat?q=%s)
1 parent 3415ad2 commit a7a4d49

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/routes/chat/+layout.svelte

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,20 @@
522522
},
523523
},
524524
});
525+
526+
let hasAutoSubmitted = $state(false);
527+
528+
// Auto-submit when URL query parameter is present (only once)
529+
$effect(() => {
530+
const urlQuery = page.url.searchParams.get('q');
531+
if (urlQuery && message.current && !isGenerating && mounted.current && !hasAutoSubmitted) {
532+
hasAutoSubmitted = true;
533+
// Small delay to ensure everything is ready
534+
setTimeout(() => {
535+
handleSubmit();
536+
}, 100);
537+
}
538+
});
525539
let selectedImages = $state<{ url: string; storage_id: string; fileName?: string }[]>([]);
526540
let selectedDocuments = $state<
527541
{

src/routes/chat/+page.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { scale } from 'svelte/transition';
1010
import { useCachedQuery, api } from '$lib/cache/cached-query.svelte';
1111
import { Provider } from '$lib/types';
12+
import { page } from '$app/state';
1213
1314
const defaultSuggestions = [
1415
'How does AI work?',
@@ -68,6 +69,14 @@
6869
});
6970
7071
const prompt = usePrompt();
72+
73+
// Handle URL parameter for initial query
74+
$effect(() => {
75+
const urlQuery = page.url.searchParams.get('q');
76+
if (urlQuery && prompt.current === '') {
77+
prompt.current = decodeURIComponent(urlQuery);
78+
}
79+
});
7180
</script>
7281

7382
<svelte:head>

0 commit comments

Comments
 (0)