Build user pages
This commit is contained in:
@@ -1,260 +0,0 @@
|
||||
<script lang="ts">
|
||||
import TipTap from '$lib/components/tiptap/TipTap.svelte';
|
||||
|
||||
type Category = {
|
||||
id: string;
|
||||
name: string;
|
||||
parentId?: number | null;
|
||||
children?: Category[];
|
||||
};
|
||||
|
||||
type Frequency = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
type Affirmation = {
|
||||
id?: string;
|
||||
name?: string;
|
||||
content?: string;
|
||||
price?: number;
|
||||
categoryId?: string;
|
||||
solfeggioFrequencyId?: string;
|
||||
category?: { parentId?: number | null; parent?: { name: string } };
|
||||
};
|
||||
|
||||
type FormData = {
|
||||
id?: string;
|
||||
name?: string;
|
||||
content?: string;
|
||||
price?: number;
|
||||
categoryId?: string;
|
||||
categoryName?: string;
|
||||
subCategoryName?: string;
|
||||
solfeggioFrequencyId?: string;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
affirmation?: Affirmation;
|
||||
categories: Category[];
|
||||
frequencies: Frequency[];
|
||||
form?: FormData;
|
||||
action: string;
|
||||
submitLabel?: string;
|
||||
};
|
||||
|
||||
let {
|
||||
affirmation = {},
|
||||
categories,
|
||||
frequencies,
|
||||
form,
|
||||
action,
|
||||
submitLabel = 'Save Affirmation'
|
||||
}: Props = $props();
|
||||
|
||||
const topLevelCategories = $derived(categories.filter((c) => !c.parentId));
|
||||
|
||||
// Determine initial parent category name from form data or existing affirmation
|
||||
function getInitialCategoryName(): string {
|
||||
if (form?.categoryName) return form.categoryName;
|
||||
if (affirmation.category?.parent) return affirmation.category.parent.name;
|
||||
if (affirmation.categoryId) {
|
||||
const cat = categories.find((c) => c.id === affirmation.categoryId);
|
||||
if (cat?.parentId) {
|
||||
const parent = categories.find((c) => String(c.id) === String(cat.parentId));
|
||||
return parent?.name ?? '';
|
||||
}
|
||||
return cat?.name ?? '';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function getInitialSubCategoryName(): string {
|
||||
if (form?.subCategoryName) return form.subCategoryName;
|
||||
if (affirmation.categoryId) {
|
||||
const cat = categories.find((c) => c.id === affirmation.categoryId);
|
||||
if (cat?.parentId) return cat.name;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
let categoryInput = $state(getInitialCategoryName());
|
||||
let showNewCategory = $state(false);
|
||||
let newCategoryName = $state('');
|
||||
|
||||
let subCategoryInput = $state(getInitialSubCategoryName());
|
||||
let showNewSubCategory = $state(false);
|
||||
let newSubCategoryName = $state('');
|
||||
|
||||
const selectedParent = $derived(topLevelCategories.find((c) => c.name === categoryInput));
|
||||
const subCategories = $derived(selectedParent?.children ?? []);
|
||||
|
||||
function handleCategoryChange(e: Event) {
|
||||
const value = (e.target as HTMLSelectElement).value;
|
||||
if (value === '__new__') {
|
||||
showNewCategory = true;
|
||||
categoryInput = '';
|
||||
} else {
|
||||
showNewCategory = false;
|
||||
newCategoryName = '';
|
||||
categoryInput = value;
|
||||
}
|
||||
subCategoryInput = '';
|
||||
showNewSubCategory = false;
|
||||
newSubCategoryName = '';
|
||||
}
|
||||
|
||||
function handleSubCategoryChange(e: Event) {
|
||||
const value = (e.target as HTMLSelectElement).value;
|
||||
if (value === '__new__') {
|
||||
showNewSubCategory = true;
|
||||
subCategoryInput = '';
|
||||
} else {
|
||||
showNewSubCategory = false;
|
||||
newSubCategoryName = '';
|
||||
subCategoryInput = value;
|
||||
}
|
||||
}
|
||||
|
||||
const effectiveCategoryName = $derived(showNewCategory ? newCategoryName : categoryInput);
|
||||
const effectiveSubCategoryName = $derived(
|
||||
showNewSubCategory ? newSubCategoryName : subCategoryInput
|
||||
);
|
||||
</script>
|
||||
|
||||
<form method="POST" {action} class="space-y-5">
|
||||
{#if affirmation.id || form?.id}
|
||||
<input type="hidden" name="id" value={form?.id ?? affirmation.id} />
|
||||
{/if}
|
||||
|
||||
<input type="hidden" name="categoryName" value={effectiveCategoryName} />
|
||||
<input type="hidden" name="subCategoryName" value={effectiveSubCategoryName} />
|
||||
|
||||
<div>
|
||||
<label for="name" class="mb-1 block text-sm font-medium text-gray-700">Name</label>
|
||||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
name="name"
|
||||
value={form?.name ?? affirmation.name ?? ''}
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 px-3 py-2 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="mb-1 block text-sm font-medium text-gray-700" for="content">Content</label>
|
||||
<TipTap initialContent={form?.content ?? affirmation.content ?? ''} name="content" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="solfeggioFrequencyId" class="mb-1 block text-sm font-medium text-gray-700">
|
||||
Solfeggio Frequency
|
||||
</label>
|
||||
<select
|
||||
id="solfeggioFrequencyId"
|
||||
name="solfeggioFrequencyId"
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<option value="" disabled selected={!affirmation.solfeggioFrequencyId && !form?.solfeggioFrequencyId}>
|
||||
Select a frequency
|
||||
</option>
|
||||
{#each frequencies as frequency}
|
||||
<option
|
||||
value={frequency.id}
|
||||
selected={frequency.id === (form?.solfeggioFrequencyId ?? affirmation.solfeggioFrequencyId)}
|
||||
>
|
||||
{frequency.name}
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="categorySelect" class="mb-1 block text-sm font-medium text-gray-700">
|
||||
Category
|
||||
</label>
|
||||
<select
|
||||
id="categorySelect"
|
||||
onchange={handleCategoryChange}
|
||||
class="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<option value="" disabled selected={!categoryInput && !showNewCategory}>
|
||||
Select a category
|
||||
</option>
|
||||
{#each topLevelCategories as category}
|
||||
<option value={category.name} selected={category.name === categoryInput}>
|
||||
{category.name}
|
||||
</option>
|
||||
{/each}
|
||||
<option value="__new__" selected={showNewCategory}>New...</option>
|
||||
</select>
|
||||
|
||||
{#if showNewCategory}
|
||||
<input
|
||||
type="text"
|
||||
placeholder="New category name"
|
||||
bind:value={newCategoryName}
|
||||
required
|
||||
class="mt-2 w-full rounded-lg border border-gray-300 px-3 py-2 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if categoryInput || showNewCategory}
|
||||
<div>
|
||||
<label for="subCategorySelect" class="mb-1 block text-sm font-medium text-gray-700">
|
||||
Sub-category
|
||||
</label>
|
||||
<select
|
||||
id="subCategorySelect"
|
||||
onchange={handleSubCategoryChange}
|
||||
class="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<option value="" selected={!subCategoryInput && !showNewSubCategory}>None</option>
|
||||
{#each subCategories as sub}
|
||||
<option value={sub.name} selected={sub.name === subCategoryInput}>
|
||||
{sub.name}
|
||||
</option>
|
||||
{/each}
|
||||
<option value="__new__" selected={showNewSubCategory}>New...</option>
|
||||
</select>
|
||||
|
||||
{#if showNewSubCategory}
|
||||
<input
|
||||
type="text"
|
||||
placeholder="New sub-category name"
|
||||
bind:value={newSubCategoryName}
|
||||
class="mt-2 w-full rounded-lg border border-gray-300 px-3 py-2 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
<label for="price" class="mb-1 block text-sm font-medium text-gray-700">Price</label>
|
||||
<div class="relative">
|
||||
<span class="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500">$</span>
|
||||
<input
|
||||
type="number"
|
||||
id="price"
|
||||
name="price"
|
||||
value={form?.price ?? affirmation.price ?? ''}
|
||||
defaultValue={0.00}
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder="0.00"
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 py-2 pr-3 pl-7 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="rounded-lg bg-blue-600 px-4 py-2.5 font-medium text-white transition-colors hover:bg-blue-700 focus:ring-4 focus:ring-blue-200"
|
||||
>
|
||||
{submitLabel}
|
||||
</button>
|
||||
</form>
|
||||
@@ -1,62 +0,0 @@
|
||||
<script lang="ts">
|
||||
type Frequency = {
|
||||
id?: number;
|
||||
name?: string;
|
||||
value?: number;
|
||||
};
|
||||
|
||||
type FormData = {
|
||||
id?: string;
|
||||
name?: string;
|
||||
value?: string;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
frequency?: Frequency;
|
||||
form?: FormData;
|
||||
action: string;
|
||||
submitLabel?: string;
|
||||
};
|
||||
|
||||
let { frequency = {}, form, action, submitLabel = 'Save Frequency' }: Props = $props();
|
||||
</script>
|
||||
|
||||
<form method="POST" {action} class="space-y-5">
|
||||
{#if frequency.id || form?.id}
|
||||
<input type="hidden" name="id" value={form?.id ?? frequency.id} />
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
<label for="name" class="mb-1 block text-sm font-medium text-gray-700">Name</label>
|
||||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
name="name"
|
||||
value={form?.name ?? frequency.name ?? ''}
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 px-3 py-2 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="value" class="mb-1 block text-sm font-medium text-gray-700">Frequency (Hz)</label>
|
||||
<input
|
||||
type="number"
|
||||
id="value"
|
||||
name="value"
|
||||
value={form?.value ?? frequency.value ?? ''}
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder="e.g. 396"
|
||||
required
|
||||
class="w-full rounded-lg border border-gray-300 px-3 py-2 outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="rounded-lg bg-blue-600 px-4 py-2.5 font-medium text-white transition-colors hover:bg-blue-700 focus:ring-4 focus:ring-blue-200"
|
||||
>
|
||||
{submitLabel}
|
||||
</button>
|
||||
</form>
|
||||
@@ -1,242 +0,0 @@
|
||||
<script lang="ts">
|
||||
type Affirmation = {
|
||||
id: string;
|
||||
name: string;
|
||||
content: string;
|
||||
price: number;
|
||||
solfeggioFrequency?: {
|
||||
name: string;
|
||||
value: number;
|
||||
};
|
||||
category?: {
|
||||
name: string;
|
||||
parent?: { name: string } | null;
|
||||
};
|
||||
};
|
||||
|
||||
function categoryDisplayName(category?: Affirmation['category']): string {
|
||||
if (!category) return '';
|
||||
if (category.parent) return `${category.parent.name} > ${category.name}`;
|
||||
return category.name;
|
||||
}
|
||||
|
||||
type SortKey = 'name' | 'category' | 'frequency' | 'price';
|
||||
type SortDirection = 'asc' | 'desc';
|
||||
|
||||
type Props = {
|
||||
affirmations: Affirmation[];
|
||||
};
|
||||
|
||||
let { affirmations }: Props = $props();
|
||||
|
||||
let search = $state('');
|
||||
let categoryFilter = $state('');
|
||||
let frequencyFilter = $state('');
|
||||
let sortKey = $state<SortKey>('name');
|
||||
let sortDirection = $state<SortDirection>('asc');
|
||||
|
||||
const categories = $derived([...new Set(affirmations.map((a) => categoryDisplayName(a.category)).filter(Boolean))].sort());
|
||||
const frequencies = $derived([...new Set(affirmations.map((a) => a.solfeggioFrequency?.name).filter(Boolean))].sort());
|
||||
|
||||
const filteredAndSorted = $derived(() => {
|
||||
let result = affirmations;
|
||||
|
||||
// Search filter
|
||||
if (search) {
|
||||
const searchLower = search.toLowerCase();
|
||||
result = result.filter(
|
||||
(a) =>
|
||||
a.name.toLowerCase().includes(searchLower) ||
|
||||
a.content.toLowerCase().includes(searchLower) ||
|
||||
categoryDisplayName(a.category).toLowerCase().includes(searchLower) ||
|
||||
a.solfeggioFrequency?.name.toLowerCase().includes(searchLower)
|
||||
);
|
||||
}
|
||||
|
||||
// Category filter
|
||||
if (categoryFilter) {
|
||||
result = result.filter((a) => categoryDisplayName(a.category) === categoryFilter);
|
||||
}
|
||||
|
||||
// Frequency filter
|
||||
if (frequencyFilter) {
|
||||
result = result.filter((a) => a.solfeggioFrequency?.name === frequencyFilter);
|
||||
}
|
||||
|
||||
// Sort
|
||||
result = [...result].sort((a, b) => {
|
||||
let aVal: string | number;
|
||||
let bVal: string | number;
|
||||
|
||||
switch (sortKey) {
|
||||
case 'name':
|
||||
aVal = a.name.toLowerCase();
|
||||
bVal = b.name.toLowerCase();
|
||||
break;
|
||||
case 'category':
|
||||
aVal = categoryDisplayName(a.category).toLowerCase();
|
||||
bVal = categoryDisplayName(b.category).toLowerCase();
|
||||
break;
|
||||
case 'frequency':
|
||||
aVal = a.solfeggioFrequency?.value ?? 0;
|
||||
bVal = b.solfeggioFrequency?.value ?? 0;
|
||||
break;
|
||||
case 'price':
|
||||
aVal = a.price;
|
||||
bVal = b.price;
|
||||
break;
|
||||
}
|
||||
|
||||
if (aVal < bVal) return sortDirection === 'asc' ? -1 : 1;
|
||||
if (aVal > bVal) return sortDirection === 'asc' ? 1 : -1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
function toggleSort(key: SortKey) {
|
||||
if (sortKey === key) {
|
||||
sortDirection = sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
sortKey = key;
|
||||
sortDirection = 'asc';
|
||||
}
|
||||
}
|
||||
|
||||
function getSortIndicator(key: SortKey) {
|
||||
if (sortKey !== key) return '↕';
|
||||
return sortDirection === 'asc' ? '↑' : '↓';
|
||||
}
|
||||
|
||||
function clearFilters() {
|
||||
search = '';
|
||||
categoryFilter = '';
|
||||
frequencyFilter = '';
|
||||
}
|
||||
|
||||
const hasActiveFilters = $derived(search || categoryFilter || frequencyFilter);
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search affirmations..."
|
||||
bind:value={search}
|
||||
class="rounded-lg border border-gray-300 px-3 py-2 text-sm outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
|
||||
<select
|
||||
bind:value={categoryFilter}
|
||||
class="min-w-40 rounded-lg border border-gray-300 bg-white px-3 py-2 pr-8 text-sm outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<option value="">All Categories</option>
|
||||
{#each categories as category}
|
||||
<option value={category}>{category}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
<select
|
||||
bind:value={frequencyFilter}
|
||||
class="min-w-40 rounded-lg border border-gray-300 bg-white px-3 py-2 pr-8 text-sm outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<option value="">All Frequencies</option>
|
||||
{#each frequencies as frequency}
|
||||
<option value={frequency}>{frequency}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
{#if hasActiveFilters}
|
||||
<button
|
||||
type="button"
|
||||
onclick={clearFilters}
|
||||
class="rounded-lg px-3 py-2 text-sm text-gray-500 hover:bg-gray-100 hover:text-gray-700"
|
||||
>
|
||||
Clear filters
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<span class="ml-auto text-sm text-gray-500">
|
||||
{filteredAndSorted().length} of {affirmations.length}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full border-collapse text-left text-sm">
|
||||
<thead>
|
||||
<tr class="border-b border-gray-200 bg-gray-50">
|
||||
<th class="px-4 py-3 font-medium text-gray-700">
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1 hover:text-gray-900"
|
||||
onclick={() => toggleSort('name')}
|
||||
>
|
||||
Name
|
||||
<span class="text-xs text-gray-400">{getSortIndicator('name')}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-3 font-medium text-gray-700">
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1 hover:text-gray-900"
|
||||
onclick={() => toggleSort('category')}
|
||||
>
|
||||
Category
|
||||
<span class="text-xs text-gray-400">{getSortIndicator('category')}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-3 font-medium text-gray-700">
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1 hover:text-gray-900"
|
||||
onclick={() => toggleSort('frequency')}
|
||||
>
|
||||
Frequency
|
||||
<span class="text-xs text-gray-400">{getSortIndicator('frequency')}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-3 text-right font-medium text-gray-700">
|
||||
<button
|
||||
type="button"
|
||||
class="ml-auto flex items-center gap-1 hover:text-gray-900"
|
||||
onclick={() => toggleSort('price')}
|
||||
>
|
||||
Price
|
||||
<span class="text-xs text-gray-400">{getSortIndicator('price')}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-3 font-medium text-gray-700"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each filteredAndSorted() as affirmation}
|
||||
<tr class="border-b border-gray-100 hover:bg-gray-50">
|
||||
<td class="px-4 py-3 font-medium text-gray-900">{affirmation.name}</td>
|
||||
<td class="px-4 py-3 text-gray-600">{categoryDisplayName(affirmation.category) || '—'}</td>
|
||||
<td class="px-4 py-3 text-gray-600">{affirmation.solfeggioFrequency?.name ?? '—'}</td>
|
||||
<td class="px-4 py-3 text-right text-gray-600">${affirmation.price.toFixed(2)}</td>
|
||||
<td class="px-4 py-3 text-right">
|
||||
<a
|
||||
href="/affirmations/{affirmation.id}"
|
||||
class="text-blue-600 hover:text-blue-800 hover:underline"
|
||||
>
|
||||
Edit
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr>
|
||||
<td colspan="5" class="px-4 py-8 text-center text-gray-500">
|
||||
{#if hasActiveFilters}
|
||||
No affirmations match your filters
|
||||
{:else}
|
||||
No affirmations yet
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,176 +0,0 @@
|
||||
<script lang="ts">
|
||||
type Frequency = {
|
||||
id: number;
|
||||
name: string;
|
||||
value: number;
|
||||
_count?: {
|
||||
affirmations: number;
|
||||
};
|
||||
};
|
||||
|
||||
type SortKey = 'name' | 'value' | 'affirmations';
|
||||
type SortDirection = 'asc' | 'desc';
|
||||
|
||||
type Props = {
|
||||
frequencies: Frequency[];
|
||||
};
|
||||
|
||||
let { frequencies }: Props = $props();
|
||||
|
||||
let search = $state('');
|
||||
let sortKey = $state<SortKey>('name');
|
||||
let sortDirection = $state<SortDirection>('asc');
|
||||
|
||||
const filteredAndSorted = $derived(() => {
|
||||
let result = frequencies;
|
||||
|
||||
if (search) {
|
||||
const searchLower = search.toLowerCase();
|
||||
result = result.filter(
|
||||
(f) =>
|
||||
f.name.toLowerCase().includes(searchLower) ||
|
||||
f.value.toString().includes(searchLower)
|
||||
);
|
||||
}
|
||||
|
||||
result = [...result].sort((a, b) => {
|
||||
let aVal: string | number;
|
||||
let bVal: string | number;
|
||||
|
||||
switch (sortKey) {
|
||||
case 'name':
|
||||
aVal = a.name.toLowerCase();
|
||||
bVal = b.name.toLowerCase();
|
||||
break;
|
||||
case 'value':
|
||||
aVal = a.value;
|
||||
bVal = b.value;
|
||||
break;
|
||||
case 'affirmations':
|
||||
aVal = a._count?.affirmations ?? 0;
|
||||
bVal = b._count?.affirmations ?? 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (aVal < bVal) return sortDirection === 'asc' ? -1 : 1;
|
||||
if (aVal > bVal) return sortDirection === 'asc' ? 1 : -1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
function toggleSort(key: SortKey) {
|
||||
if (sortKey === key) {
|
||||
sortDirection = sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
sortKey = key;
|
||||
sortDirection = 'asc';
|
||||
}
|
||||
}
|
||||
|
||||
function getSortIndicator(key: SortKey) {
|
||||
if (sortKey !== key) return '\u21D5';
|
||||
return sortDirection === 'asc' ? '\u2191' : '\u2193';
|
||||
}
|
||||
|
||||
function clearFilters() {
|
||||
search = '';
|
||||
}
|
||||
|
||||
const hasActiveFilters = $derived(!!search);
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search frequencies..."
|
||||
bind:value={search}
|
||||
class="rounded-lg border border-gray-300 px-3 py-2 text-sm outline-none transition-shadow focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
|
||||
{#if hasActiveFilters}
|
||||
<button
|
||||
type="button"
|
||||
onclick={clearFilters}
|
||||
class="rounded-lg px-3 py-2 text-sm text-gray-500 hover:bg-gray-100 hover:text-gray-700"
|
||||
>
|
||||
Clear filters
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<span class="ml-auto text-sm text-gray-500">
|
||||
{filteredAndSorted().length} of {frequencies.length}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full border-collapse text-left text-sm">
|
||||
<thead>
|
||||
<tr class="border-b border-gray-200 bg-gray-50">
|
||||
<th class="px-4 py-3 font-medium text-gray-700">
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1 hover:text-gray-900"
|
||||
onclick={() => toggleSort('name')}
|
||||
>
|
||||
Name
|
||||
<span class="text-xs text-gray-400">{getSortIndicator('name')}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-3 text-right font-medium text-gray-700">
|
||||
<button
|
||||
type="button"
|
||||
class="ml-auto flex items-center gap-1 hover:text-gray-900"
|
||||
onclick={() => toggleSort('value')}
|
||||
>
|
||||
Frequency (Hz)
|
||||
<span class="text-xs text-gray-400">{getSortIndicator('value')}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-3 text-right font-medium text-gray-700">
|
||||
<button
|
||||
type="button"
|
||||
class="ml-auto flex items-center gap-1 hover:text-gray-900"
|
||||
onclick={() => toggleSort('affirmations')}
|
||||
>
|
||||
Affirmations
|
||||
<span class="text-xs text-gray-400">{getSortIndicator('affirmations')}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-3 font-medium text-gray-700"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each filteredAndSorted() as frequency}
|
||||
<tr class="border-b border-gray-100 hover:bg-gray-50">
|
||||
<td class="px-4 py-3 font-medium text-gray-900">{frequency.name}</td>
|
||||
<td class="px-4 py-3 text-right text-gray-600">{frequency.value} Hz</td>
|
||||
<td class="px-4 py-3 text-right text-gray-600">
|
||||
{frequency._count?.affirmations ?? 0}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-right">
|
||||
<a
|
||||
href="/frequencies/{frequency.id}"
|
||||
class="text-blue-600 hover:text-blue-800 hover:underline"
|
||||
>
|
||||
Edit
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr>
|
||||
<td colspan="4" class="px-4 py-8 text-center text-gray-500">
|
||||
{#if hasActiveFilters}
|
||||
No frequencies match your filters
|
||||
{:else}
|
||||
No frequencies yet
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,15 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { authClient } from '$lib/auth-client';
|
||||
import { canAccessAdmin } from '$lib/svelte-admin/roles';
|
||||
|
||||
let { userRoleId = null }: { userRoleId: number | null } = $props();
|
||||
const session = authClient.useSession();
|
||||
let isAdmin = $derived(canAccessAdmin(userRoleId));
|
||||
</script>
|
||||
|
||||
<nav class="flex w-full justify-between px-8 py-6">
|
||||
<span><a href="/">Rhema Wave Technologies</a></span>
|
||||
{#if $session.data}
|
||||
<div>
|
||||
{#if isAdmin}
|
||||
<a href="/admin" class="mx-2">Admin Panel</a>
|
||||
{/if}
|
||||
<a href="/dashboard" class="mx-2">Dashboard</a>
|
||||
<button
|
||||
on:click={async () => {
|
||||
onclick={async () => {
|
||||
authClient.signOut();
|
||||
}}>Log Out</button
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user