Compare commits
13 Commits
supabase-l
...
b0e530ed62
| Author | SHA1 | Date | |
|---|---|---|---|
| b0e530ed62 | |||
|
|
a8f1b973e6 | ||
|
|
308e70941f | ||
|
|
5a09b50e82 | ||
| c18a67e926 | |||
|
|
a11bd416bf | ||
|
|
5751c6d6dc | ||
| 45fa8b3005 | |||
| c97acffe5b | |||
| 99f2b778e5 | |||
| 0a556f144c | |||
| 9c99a88bb0 | |||
| 15d2426ce6 |
5
.github/copilot-instructions.md
vendored
5
.github/copilot-instructions.md
vendored
@@ -1,11 +1,14 @@
|
||||
GitHub Copilot Instructions for This Repository
|
||||
|
||||
Basics:
|
||||
Basics: These you need to really follow!
|
||||
- If you have any questions, always ask me first!
|
||||
- Use Svelte 5 runes exclusively
|
||||
- Declare reactive state with $state(); derive values with $derived(); run side-effect logic with $effect() etc.
|
||||
- When doing client-side loading, always implement placeholders and loaders, so the UI remains responsive and layout shifts are minimized.
|
||||
- Don't use placeholders and loaders for static data like heading etc.
|
||||
- Never use supabse-js. I am using supabse-ssr and supabase client is located in:
|
||||
- client: $props.data.supabse
|
||||
- server: $locals.supabase
|
||||
|
||||
Do not fall back to the legacy $: label syntax or Svelte 3/4 stores! This is important!
|
||||
|
||||
|
||||
27
package-lock.json
generated
27
package-lock.json
generated
@@ -11,6 +11,7 @@
|
||||
"@supabase/ssr": "^0.6.1",
|
||||
"@supabase/supabase-js": "^2.50.0",
|
||||
"@sveltejs/adapter-node": "^5.2.12",
|
||||
"@tanstack/svelte-query": "^5.83.0",
|
||||
"googleapis": "^150.0.1",
|
||||
"papaparse": "^5.5.3",
|
||||
"qrcode": "^1.5.4",
|
||||
@@ -1382,6 +1383,32 @@
|
||||
"vite": "^5.2.0 || ^6"
|
||||
}
|
||||
},
|
||||
"node_modules/@tanstack/query-core": {
|
||||
"version": "5.83.0",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.83.0.tgz",
|
||||
"integrity": "sha512-0M8dA+amXUkyz5cVUm/B+zSk3xkQAcuXuz5/Q/LveT4ots2rBpPTZOzd7yJa2Utsf8D2Upl5KyjhHRY+9lB/XA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/tannerlinsley"
|
||||
}
|
||||
},
|
||||
"node_modules/@tanstack/svelte-query": {
|
||||
"version": "5.83.0",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/svelte-query/-/svelte-query-5.83.0.tgz",
|
||||
"integrity": "sha512-8tNXhuoizntZXnAzo4yqUWgZZnklQkXGUNpb3YreW68DyCBhhrGbErnrODQs3fVc2ABcMvAHIki5uErbdzXH1A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tanstack/query-core": "5.83.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/tannerlinsley"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"svelte": "^3.54.0 || ^4.0.0 || ^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/cookie": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz",
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
"@supabase/ssr": "^0.6.1",
|
||||
"@supabase/supabase-js": "^2.50.0",
|
||||
"@sveltejs/adapter-node": "^5.2.12",
|
||||
"@tanstack/svelte-query": "^5.83.0",
|
||||
"googleapis": "^150.0.1",
|
||||
"papaparse": "^5.5.3",
|
||||
"qrcode": "^1.5.4",
|
||||
|
||||
9
src/lib/helpers.ts
Normal file
9
src/lib/helpers.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
export const reactiveQueryArgs = <T>(cb: () => T) => {
|
||||
const store = writable<T>();
|
||||
$effect.pre(() => {
|
||||
store.set(cb());
|
||||
});
|
||||
return store;
|
||||
};
|
||||
@@ -1,21 +1,34 @@
|
||||
<script lang="ts">
|
||||
// Add any navbar logic here if needed
|
||||
import { browser } from '$app/environment';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
enabled: browser,
|
||||
staleTime: 5 * 60_000, // 5 min cache
|
||||
refetchOnWindowFocus: false
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<nav class="bg-gray-50 border-b border-gray-300 text-gray-900 p-2">
|
||||
<div class="container max-w-2xl mx-auto p-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="font-bold text-lg">ScanWave</div>
|
||||
|
||||
<ul class="flex space-x-4">
|
||||
<li><a href="/private/home" class="hover:underline">Home</a></li>
|
||||
<li><a href="/private/scanner" class="hover:underline">Scanner</a></li>
|
||||
<li><a href="/private/events" class="hover:underline">Events</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<nav class="border-b border-gray-300 bg-gray-50 p-2 text-gray-900">
|
||||
<div class="container mx-auto max-w-2xl p-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="text-lg font-bold">ScanWave</div>
|
||||
|
||||
<ul class="flex space-x-4">
|
||||
<li><a href="/private/home">Home</a></li>
|
||||
<li><a href="/private/scanner">Scanner</a></li>
|
||||
<li><a href="/private/events">Events</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container max-w-2xl mx-auto p-2 bg-white">
|
||||
<slot />
|
||||
</div>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<div class="container mx-auto max-w-2xl bg-white p-2">
|
||||
<slot />
|
||||
</div>
|
||||
</QueryClientProvider>
|
||||
|
||||
@@ -16,6 +16,16 @@ interface EmailResult {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces template variables in a string with participant data
|
||||
* Currently supports {name} and {surname} placeholders
|
||||
*/
|
||||
function replaceTemplateVariables(template: string, participant: Participant): string {
|
||||
return template
|
||||
.replace(/{name}/gi, participant.name || '')
|
||||
.replace(/{surname}/gi, participant.surname || '');
|
||||
}
|
||||
|
||||
async function generateQRCode(participantId: string): Promise<string> {
|
||||
const qrCodeBase64 = await QRCode.toDataURL(participantId, {
|
||||
type: 'image/png',
|
||||
@@ -38,11 +48,15 @@ async function sendEmailToParticipant(
|
||||
try {
|
||||
const qrCodeBase64Data = await generateQRCode(participant.id);
|
||||
|
||||
// Replace template variables in subject and body
|
||||
const personalizedSubject = replaceTemplateVariables(subject, participant);
|
||||
const personalizedText = replaceTemplateVariables(text, participant);
|
||||
|
||||
// Send email with QR code
|
||||
await sendGmail(refreshToken, {
|
||||
to: participant.email,
|
||||
subject: subject,
|
||||
text: text,
|
||||
subject: personalizedSubject,
|
||||
text: personalizedText,
|
||||
qr_code: qrCodeBase64Data
|
||||
});
|
||||
|
||||
|
||||
@@ -1,150 +1,64 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import SingleEvent from './SingleEvent.svelte';
|
||||
import { createQuery } from '@tanstack/svelte-query';
|
||||
import { getEvents } from './queries';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
// Get Supabase client from props
|
||||
let { data } = $props();
|
||||
|
||||
// Types
|
||||
interface Event {
|
||||
id: string;
|
||||
name: string;
|
||||
date: string;
|
||||
archived: boolean; // Whether the event is from events_archived table
|
||||
}
|
||||
// Reactive state for search input and debounced search term
|
||||
let searchInput = $state('');
|
||||
let debouncedSearch = writable('');
|
||||
let searchTimeout: ReturnType<typeof setTimeout>;
|
||||
|
||||
// State
|
||||
let allEvents = $state<Event[]>([]); // All events from both tables
|
||||
let displayEvents = $state<Event[]>([]); // Events to display (filtered by search)
|
||||
let loading = $state(true);
|
||||
let error = $state('');
|
||||
let searchTerm = $state('');
|
||||
let isSearching = $state(false);
|
||||
let searchTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
onMount(async () => {
|
||||
await loadEvents();
|
||||
});
|
||||
|
||||
async function loadEvents() {
|
||||
loading = true;
|
||||
error = '';
|
||||
try {
|
||||
// Fetch regular events
|
||||
const { data: eventsData, error: eventsError } = await data.supabase
|
||||
.from('events')
|
||||
.select('id, name, date')
|
||||
.order('date', { ascending: false });
|
||||
|
||||
if (eventsError) throw eventsError;
|
||||
|
||||
// Fetch archived events (limited to 20)
|
||||
const { data: archivedEventsData, error: archivedError } = await data.supabase
|
||||
.from('events_archived')
|
||||
.select('id, name, date')
|
||||
.order('date', { ascending: false })
|
||||
.limit(20);
|
||||
|
||||
if (archivedError) throw archivedError;
|
||||
|
||||
// Merge both arrays, marking archived events
|
||||
const regularEvents = (eventsData || []).map(event => ({ ...event, archived: false }));
|
||||
const archivedEvents = (archivedEventsData || []).map(event => ({ ...event, archived: true }));
|
||||
|
||||
// Sort all events by date (newest first)
|
||||
const combined = [...regularEvents, ...archivedEvents];
|
||||
|
||||
allEvents = combined;
|
||||
displayEvents = allEvents;
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error loading events:', err);
|
||||
error = 'Failed to load events';
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(dateString: string) {
|
||||
return new Date(dateString).toLocaleDateString('en-GB', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
async function searchEvents(term: string) {
|
||||
if (!term.trim()) {
|
||||
displayEvents = allEvents;
|
||||
return;
|
||||
}
|
||||
|
||||
isSearching = true;
|
||||
error = '';
|
||||
|
||||
try {
|
||||
// Search regular events
|
||||
const { data: regularResults, error: regularError } = await data.supabase
|
||||
.from('events')
|
||||
.select('id, name, date')
|
||||
.ilike('name', `%${term}%`)
|
||||
.order('date', { ascending: false });
|
||||
|
||||
if (regularError) {
|
||||
console.error('Regular events search error:', regularError);
|
||||
throw regularError;
|
||||
}
|
||||
|
||||
// Search archived events
|
||||
const { data: archivedResults, error: archivedError } = await data.supabase
|
||||
.from('events_archived')
|
||||
.select('id, name, date')
|
||||
.ilike('name', `%${term}%`)
|
||||
.order('date', { ascending: false })
|
||||
.limit(50);
|
||||
|
||||
if (archivedError) {
|
||||
console.error('Archived events search error:', archivedError);
|
||||
throw archivedError;
|
||||
}
|
||||
|
||||
// Merge search results
|
||||
const regularEvents = (regularResults || []).map(event => ({ ...event, archived: false }));
|
||||
const archivedEvents = (archivedResults || []).map(event => ({ ...event, archived: true }));
|
||||
|
||||
// Sort merged results by date (newest first)
|
||||
const combined = [...regularEvents, ...archivedEvents];
|
||||
combined.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
||||
|
||||
displayEvents = combined;
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error searching events:', err);
|
||||
} finally {
|
||||
isSearching = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle search term changes
|
||||
// Debounce the search input
|
||||
function handleSearchInput() {
|
||||
if (searchTimeout) {
|
||||
clearTimeout(searchTimeout);
|
||||
}
|
||||
|
||||
searchTimeout = setTimeout(() => {
|
||||
searchEvents(searchTerm);
|
||||
debouncedSearch.set(searchInput);
|
||||
}, 300);
|
||||
}
|
||||
|
||||
const eventsQuery = $derived(
|
||||
createQuery({
|
||||
queryKey: ['refetch', $debouncedSearch],
|
||||
queryFn: async () => getEvents(data.supabase, $debouncedSearch)
|
||||
})
|
||||
);
|
||||
|
||||
// Derived values for UI state
|
||||
let isLoading = $derived($eventsQuery.isLoading || $eventsQuery.isFetching);
|
||||
let displayEvents = $derived($eventsQuery.data || []);
|
||||
let hasError = $derived(!!$eventsQuery.error);
|
||||
let errorMessage = $derived($eventsQuery.error?.message);
|
||||
|
||||
// Format date helper function
|
||||
function formatDate(dateString: string) {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-GB', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
// Clear search function
|
||||
function clearSearch() {
|
||||
searchTerm = '';
|
||||
displayEvents = allEvents;
|
||||
searchInput = '';
|
||||
debouncedSearch.set('');
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1 class="text-2xl font-bold mb-4 mt-2 text-center">All Events</h1>
|
||||
<h1 class="mt-2 mb-4 text-center text-2xl font-bold">
|
||||
{$debouncedSearch ? `Search Results: "${$debouncedSearch}"` : 'All Events'}
|
||||
</h1>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 max-w-2xl mx-auto">
|
||||
{#if loading}
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 max-w-2xl mx-auto mb-10">
|
||||
{#if isLoading}
|
||||
<!-- Loading placeholders -->
|
||||
{#each Array(4) as _}
|
||||
<div class="block border border-gray-300 rounded bg-white p-4 min-h-[72px]">
|
||||
@@ -154,15 +68,9 @@
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{:else if error}
|
||||
{:else if hasError}
|
||||
<div class="col-span-full text-center py-8">
|
||||
<p class="text-red-600">{error}</p>
|
||||
<button
|
||||
onclick={loadEvents}
|
||||
class="mt-2 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"
|
||||
>
|
||||
Try Again
|
||||
</button>
|
||||
<p class="text-red-600">{errorMessage}</p>
|
||||
</div>
|
||||
{:else if displayEvents.length === 0}
|
||||
<div class="col-span-full text-center py-8">
|
||||
@@ -181,38 +89,70 @@
|
||||
</div>
|
||||
|
||||
<!-- Bottom actions - Mobile optimized -->
|
||||
<div class="fixed bottom-0 left-0 right-0 z-50 bg-white border-t border-gray-300 shadow-lg pb-safe">
|
||||
<div class="pb-safe fixed right-0 bottom-0 left-0 z-50 border-t border-gray-300 bg-white">
|
||||
<!-- Search bar and New Event button layout -->
|
||||
<div class="max-w-2xl mx-auto px-4 py-3 flex flex-col sm:flex-row gap-3 sm:items-center">
|
||||
<div class="mx-auto flex max-w-2xl flex-col gap-3 px-4 py-3 sm:flex-row sm:items-center">
|
||||
<!-- Search bar - Full width on mobile, adaptive on desktop -->
|
||||
<div class="relative flex-grow">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={searchTerm}
|
||||
bind:value={searchInput}
|
||||
oninput={handleSearchInput}
|
||||
placeholder="Search events..."
|
||||
class="w-full pl-10 pr-10 py-2.5 rounded-lg border border-gray-300 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
class="w-full rounded-lg border border-gray-300 py-2.5 pr-10 pl-10 text-sm focus:border-transparent focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
||||
/>
|
||||
<div class="absolute left-3 top-1/2 -translate-y-1/2">
|
||||
{#if isSearching}
|
||||
<svg class="animate-spin h-4 w-4 text-gray-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
<div class="absolute top-1/2 left-3 -translate-y-1/2">
|
||||
{#if isLoading}
|
||||
<svg
|
||||
class="h-4 w-4 animate-spin text-gray-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"
|
||||
></circle>
|
||||
<path
|
||||
class="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
></path>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg class="h-4 w-4 text-gray-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
|
||||
<svg
|
||||
class="h-4 w-4 text-gray-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
|
||||
/>
|
||||
</svg>
|
||||
{/if}
|
||||
</div>
|
||||
{#if searchTerm}
|
||||
{#if searchInput}
|
||||
<button
|
||||
onclick={clearSearch}
|
||||
class="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600"
|
||||
class="absolute top-1/2 right-3 -translate-y-1/2 text-gray-400 hover:text-gray-600"
|
||||
aria-label="Clear search"
|
||||
>
|
||||
<svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
||||
<svg
|
||||
class="h-4 w-4"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
{/if}
|
||||
@@ -221,11 +161,22 @@
|
||||
<!-- New Event button - Adaptive width -->
|
||||
<a
|
||||
href="/private/events/event/new"
|
||||
class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2.5 px-6 rounded-lg transition text-center whitespace-nowrap sm:flex-shrink-0"
|
||||
class="rounded-lg bg-blue-600 px-6 py-2.5 text-center font-bold whitespace-nowrap text-white transition hover:bg-blue-700 sm:flex-shrink-0"
|
||||
>
|
||||
<span class="flex items-center justify-center gap-2">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="h-5 w-5"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M12 4v16m8-8H4"
|
||||
/>
|
||||
</svg>
|
||||
New Event
|
||||
</span>
|
||||
@@ -234,4 +185,4 @@
|
||||
</div>
|
||||
|
||||
<!-- Add padding to bottom of content to prevent overlap with fixed bottom bar -->
|
||||
<div class="h-24"></div>
|
||||
<div class="h-24"></div>
|
||||
|
||||
@@ -6,38 +6,69 @@
|
||||
};
|
||||
errors: Record<string, string>;
|
||||
}>();
|
||||
|
||||
const templateVariables = [
|
||||
{ name: '{name}', description: "Participant's first name" },
|
||||
{ name: '{surname}', description: "Participant's last name" }
|
||||
];
|
||||
|
||||
const subjectTemplatesDetected = $derived(
|
||||
templateVariables.filter((v) => emailData.subject && emailData.subject.includes(v.name))
|
||||
);
|
||||
const bodyTemplatesDetected = $derived(
|
||||
templateVariables.filter((v) => emailData.body && emailData.body.includes(v.name))
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<label for="emailSubject" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
<label for="emailSubject" class="mb-2 block text-sm font-medium text-gray-700">
|
||||
Email Subject *
|
||||
</label>
|
||||
<input
|
||||
id="emailSubject"
|
||||
type="text"
|
||||
bind:value={emailData.subject}
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
class="w-full rounded border border-gray-300 px-3 py-2 focus:border-transparent focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
||||
placeholder="Event invitation subject"
|
||||
/>
|
||||
{#if subjectTemplatesDetected.length > 0}
|
||||
<p class="mt-1 text-xs text-gray-500">
|
||||
Detected templates: {subjectTemplatesDetected.map((v) => v.name).join(', ')}
|
||||
</p>
|
||||
{/if}
|
||||
{#if errors.subject}
|
||||
<p class="mt-1 text-sm text-red-600">{errors.subject}</p>
|
||||
<p class="text-sm text-red-600">{errors.subject}</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="emailBody" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
<label for="emailBody" class="mb-2 block text-sm font-medium text-gray-700">
|
||||
Email Body *
|
||||
</label>
|
||||
<textarea
|
||||
id="emailBody"
|
||||
bind:value={emailData.body}
|
||||
rows="8"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
class="w-full rounded border border-gray-300 px-3 py-2 focus:border-transparent focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
||||
placeholder="Email message content..."
|
||||
></textarea>
|
||||
{#if bodyTemplatesDetected.length > 0}
|
||||
<p class="text-xs text-gray-500">
|
||||
Detected templates: {bodyTemplatesDetected.map((v) => v.name).join(', ')}
|
||||
</p>
|
||||
{/if}
|
||||
{#if errors.body}
|
||||
<p class="mt-1 text-sm text-red-600">{errors.body}</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mt-2 mb-2 block text-sm font-medium text-gray-700">Tip:</p>
|
||||
<p class="text-xs text-gray-500">
|
||||
Use <code class="rounded bg-gray-100 px-1 py-0.5 text-xs">{name}</code> and
|
||||
<code class="rounded bg-gray-100 px-1 py-0.5 text-xs">{surname}</code> to personalize
|
||||
your message. Works for both subject and body. (e.g., "Hello {name}, welcome to our event!")
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
71
src/routes/private/events/queries.ts
Normal file
71
src/routes/private/events/queries.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import type { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
export interface Event {
|
||||
id: string;
|
||||
name: string;
|
||||
date: string;
|
||||
archived: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unified function to get events or search events based on a search term
|
||||
* @param supabase The Supabase client
|
||||
* @param searchTerm Optional search term - if provided, will filter by name
|
||||
* @returns Combined array of regular and archived events
|
||||
*/
|
||||
export async function getEvents(supabase: SupabaseClient, searchTerm: string = '') {
|
||||
try {
|
||||
const searchPattern = searchTerm.trim() ? `%${searchTerm}%` : null;
|
||||
|
||||
// Build regular events query
|
||||
let regularQuery = supabase
|
||||
.from('events')
|
||||
.select('id, name, date')
|
||||
.order('date', { ascending: false });
|
||||
|
||||
// Apply search filter if needed
|
||||
if (searchPattern) {
|
||||
regularQuery = regularQuery.ilike('name', searchPattern);
|
||||
}
|
||||
|
||||
// Fetch regular events
|
||||
const { data: regularEvents, error: regularError } = await regularQuery;
|
||||
|
||||
if (regularError) throw regularError;
|
||||
|
||||
// Build archived events query
|
||||
let archivedQuery = supabase
|
||||
.from('events_archived')
|
||||
.select('id, name, date')
|
||||
.order('date', { ascending: false })
|
||||
.limit(searchPattern ? 50 : 20); // Fetch more when searching
|
||||
|
||||
// Apply search filter if needed
|
||||
if (searchPattern) {
|
||||
archivedQuery = archivedQuery.ilike('name', searchPattern);
|
||||
}
|
||||
|
||||
// Fetch archived events
|
||||
const { data: archivedEvents, error: archivedError } = await archivedQuery;
|
||||
|
||||
if (archivedError) throw archivedError;
|
||||
|
||||
// Merge both arrays, marking archived events
|
||||
const regularMapped = (regularEvents || []).map((event) => ({ ...event, archived: false }));
|
||||
const archivedMapped = (archivedEvents || []).map((event) => ({
|
||||
...event,
|
||||
archived: true
|
||||
}));
|
||||
|
||||
// Sort all events by date (newest first)
|
||||
const combined = [...regularMapped, ...archivedMapped];
|
||||
combined.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
||||
|
||||
return combined;
|
||||
} catch (error) {
|
||||
console.error('Error fetching events:', error);
|
||||
throw new Error(searchTerm.trim()
|
||||
? `Failed to search events for "${searchTerm}"`
|
||||
: 'Failed to load events');
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="border border-gray-300 rounded-lg overflow-hidden h-[200px]">
|
||||
<div class="border border-gray-300 rounded-lg overflow-hidden h-[200px] mb-4">
|
||||
<div class="h-full flex flex-col">
|
||||
{#if scan_state === ScanState.scanning}
|
||||
<div class="bg-gray-50 p-4 flex-1 flex flex-col justify-center items-center">
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<p>setup</p>
|
||||
Reference in New Issue
Block a user