Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions programmerbar-web/src/lib/api/sanity/echo-cms.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import groq from 'groq';
import imageUrlBuilder from '@sanity/image-url';
import type { SanityImageSource } from '@sanity/image-url/lib/types/types';
import imageUrlBuilder, { type SanityImageSource } from '@sanity/image-url';
import { createClient } from '@sanity/client';

export const ECHO_SANITY_PROJECT_ID = 'pgq2pd26';
Expand Down
3 changes: 1 addition & 2 deletions programmerbar-web/src/lib/api/sanity/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type {
} from '@programmerbar/cms/types';
import { sanityClient } from './client';
import { GET_PRODUCTS_QUERY, GET_PRODUCT_BY_ID_QUERY } from '@programmerbar/cms/queries';
import type { SanityImageSource } from '@sanity/image-url/lib/types/types';
import imageUrlBuilder from '@sanity/image-url';
import imageUrlBuilder, { type SanityImageSource } from '@sanity/image-url';

const builder = imageUrlBuilder(sanityClient);

Expand Down
16 changes: 7 additions & 9 deletions programmerbar-web/src/lib/components/SEO.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@
}: Props = $props();

const baseUrl = 'https://programmer.bar';
const fullImageUrl = image.startsWith('http') ? image : `${baseUrl}${image}`;
const fullCanonicalUrl = canonical
? canonical.startsWith('http')
? canonical
: `${baseUrl}${canonical}`
: undefined;
const fullImageUrl = $derived(image.startsWith('http') ? image : `${baseUrl}${image}`);
const fullCanonicalUrl = $derived(
canonical ? (canonical.startsWith('http') ? canonical : `${baseUrl}${canonical}`) : undefined
);

const pageTitle = title === 'Programmerbar' ? title : `${title} - Programmerbar`;
const robotsContent = [noindex ? 'noindex' : 'index', nofollow ? 'nofollow' : 'follow'].join(
', '
const pageTitle = $derived(title === 'Programmerbar' ? title : `${title} - Programmerbar`);
const robotsContent = $derived(
[noindex ? 'noindex' : 'index', nofollow ? 'nofollow' : 'follow'].join(', ')
);
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const INTERVAL = 5000;
const MAX = 6;
const TOTAL_PAGES = Math.ceil(products.length / MAX);
const TOTAL_PAGES = $derived(Math.ceil(products.length / MAX));

let currentPage = $state(0);
let start = $derived(currentPage * MAX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

let { min, max, value, onUpdate, label = 'Prisområde' }: Props = $props();

let minValue = $state(value.min);
let maxValue = $state(value.max);
let minValue = $state(min);
let maxValue = $state(max);

// Update internal values when props change
$effect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
let submitText = $derived.by(() => (isUpdate ? 'Oppdater Produsent' : 'Opprett Produsent'));

let formData = $state({
name: producer.name || '',
imageId: producer.imageId || null
name: '',
imageId: null as string | null
});

// Update formData when producer prop changes
Expand Down
48 changes: 25 additions & 23 deletions programmerbar-web/src/lib/components/portal/cms/ProductForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@
});

let formData = $state({
name: product.name,
description: product.description,
sku: product.sku,
ordinaryPrice: product.ordinaryPrice,
studentPrice: product.studentPrice,
internalPrice: product.internalPrice,
credits: product.credits,
volume: product.volume,
alcoholContent: product.alcoholContent,
variants: product.variants,
producerId: product.producerId ?? '',
imageId: product.imageId,
isSoldOut: product.isSoldOut || false
name: '',
description: '',
sku: '',
ordinaryPrice: undefined as number | undefined,
studentPrice: undefined as number | undefined,
internalPrice: undefined as number | undefined,
credits: undefined as number | undefined,
volume: undefined as number | undefined,
alcoholContent: undefined as number | undefined,
variants: '',
producerId: '',
imageId: null as string | null,
isSoldOut: false
});

let selectedProductTypes = new SvelteSet<string>(product.productTypeIds || []);
let selectedProductTypes = new SvelteSet<string>();

const handleSubmit: SubmitFunction = () => {
return async ({ update }) => {
Expand All @@ -93,13 +93,13 @@
formData.name = product.name || '';
formData.description = product.description || '';
formData.sku = product.sku || '';
formData.ordinaryPrice = product.ordinaryPrice;
formData.studentPrice = product.studentPrice;
formData.internalPrice = product.internalPrice;
formData.credits = product.credits;
formData.volume = product.volume;
formData.alcoholContent = product.alcoholContent;
formData.variants = product.variants || '';
formData.ordinaryPrice = product.ordinaryPrice ?? undefined;
formData.studentPrice = product.studentPrice ?? undefined;
formData.internalPrice = product.internalPrice ?? undefined;
formData.credits = product.credits ?? undefined;
formData.volume = product.volume ?? undefined;
formData.alcoholContent = product.alcoholContent ?? undefined;
formData.variants = (product.variants as string) || '';
formData.producerId = product.producerId || '';
// Only update imageId if we don't already have one set by the user
if (!formData.imageId || formData.imageId === product.imageId) {
Expand All @@ -122,8 +122,10 @@
}
};

const producerOptions = producers?.map((p) => ({ value: p.id, label: p.name })) || [];
const productTypeOptions = productTypes?.map((pt) => ({ id: pt.id, label: pt.title })) || [];
const producerOptions = $derived(producers?.map((p) => ({ value: p.id, label: p.name })) || []);
const productTypeOptions = $derived(
productTypes?.map((pt) => ({ id: pt.id, label: pt.title })) || []
);

let studentDiscount = $derived.by(() =>
formData.ordinaryPrice && formData.studentPrice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
);
let submitText = $derived.by(() => (isUpdate ? 'Oppdater type' : 'Opprett type'));

let titleValue = $state(productType.title || '');
let titleValue = $state('');

// Update titleValue when productType prop changes
$effect(() => {
Expand Down
2 changes: 1 addition & 1 deletion programmerbar-web/src/lib/components/ui/Heading.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

let { level = 1, class: className, children, ...props }: Props = $props();

let tag = `h${level}` as const;
const tag = $derived(`h${level}` as const);
</script>

<svelte:element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

let { min, max, value, onUpdate, label = 'Prisområde' }: Props = $props();

let minValue = $state(value.min);
let maxValue = $state(value.max);
let minValue = $state(min);
let maxValue = $state(max);

// Update internal values when props change
$effect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
type EventWithTime = typeof data.event & {
startTime?: string | { hour: number; minute: number };
};
const event = data.event as EventWithTime;
const event = $derived(data.event as EventWithTime);

let shareText = $state('Del arrangementet');

let html = marked.parse(data.event.body ?? '');
const html = $derived(marked.parse(data.event.body ?? ''));

function handleShare() {
if (navigator.share) {
Expand All @@ -51,9 +51,10 @@
}

// SEO data
const eventDescription =
const eventDescription = $derived(
data.event.body?.slice(0, 160) ||
`${data.event.title} - Arrangement hos Programmerbar den ${formatDate(data.event.date)}`;
`${data.event.title} - Arrangement hos Programmerbar den ${formatDate(data.event.date)}`
);
</script>

<SEO
Expand Down
4 changes: 2 additions & 2 deletions programmerbar-web/src/routes/(app)/meny/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

let { data } = $props();

let types = extractTypes(data.products);
let breweries = extractBreweries(data.products);
const types = $derived(extractTypes(data.products));
const breweries = $derived(extractBreweries(data.products));
let filter = new FilterState();
let priceRange = $derived(extractPriceRange(data.products, filter.current.showStudentPrice));
let filteredProducts = $derived(filterProducts(data.products, filter));
Expand Down
21 changes: 11 additions & 10 deletions programmerbar-web/src/routes/(app)/produkt/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

let { data } = $props();

const html = marked(data.product.description ?? '');
const html = $derived(marked(data.product.description ?? ''));
const isAuthenticated = $derived(page.data.user);
const canClaimProduct = $derived.by(
() => isAuthenticated && data.product.priceList.credits && data.product.priceList.credits > 0
);

const variants = data.product.variants?.map((variant) => variant) ?? [];
const variants = $derived(data.product.variants?.map((variant) => variant) ?? []);

const metadata = [
const metadata = $derived([
{ title: 'Produsent', value: data.product.producer ?? 'Ingen' },
{
title: 'Alkoholinnhold',
Expand All @@ -43,14 +43,14 @@
...(data.product.priceList.credits && data.product.priceList.credits > 0
? [{ title: 'Bong pris', value: data.product.priceList.credits }]
: [])
];
]);

type ClaimFeedback = {
type: 'success' | 'error';
message: string;
};

const creditCost = data.product.priceList.credits ?? 0;
const creditCost = $derived(data.product.priceList.credits ?? 0);

let claimLoading = $state(false);
let claimFeedback = $state<ClaimFeedback | null>(null);
Expand All @@ -63,12 +63,13 @@
let imageLoaded = $state(false);

// SEO data
const productImage = data.product.image
? urlFor(data.product.image).width(2000).quality(95).url()
: undefined;
const productDescription =
const productImage = $derived(
data.product.image ? urlFor(data.product.image).width(2000).quality(95).url() : undefined
);
const productDescription = $derived(
data.product.description ||
`${data.product.name} - ${data.product.producer || 'Ukjent produsent'} - Pris fra ${data.product.priceList.student} kr`;
`${data.product.name} - ${data.product.producer || 'Ukjent produsent'} - Pris fra ${data.product.priceList.student} kr`
);

function openConfirmation() {
claimFeedback = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@

let userHasCompletedTraining = $state(data.user.isTrained || false);

$effect(() => {
user = data.user as User;
userHasCompletedTraining = data.user.isTrained || false;
});

let toastMessage = $state('');

function showToast(message: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@
import type { SubmitFunction } from './$types.js';

let { data } = $props();
let user = data.user as User;
let user = $derived(data.user as User);

let editForm = $state({
role: user.role,
phone: user.phone || '',
canRefer: user.canRefer ?? true
});

$effect(() => {
editForm.role = data.user.role;
editForm.phone = data.user.phone || '';
editForm.canRefer = data.user.canRefer ?? true;
});

let isSubmitting = $state(false);

const handleSave: SubmitFunction = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
<ul class="mt-1 space-y-1">
{#if deletedShiftIds.length > 0}
<li>
• {deletedShiftIds.length} vakt{deletedShiftIds.length > 1 ? 'er' : ''} blir slettet ved
lagring
• {deletedShiftIds.length} vakt{deletedShiftIds.length > 1 ? 'er' : ''} blir slettet ved lagring
</li>
{/if}
{#if removedUserShifts.length > 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
import type { SubmitFunction } from './$types.js';

let { data } = $props();
let user = data.user as User;
let user = $derived(data.user as User);

let editForm = $state({
altEmail: user.altEmail || '',
phone: user.phone || ''
});

$effect(() => {
editForm.altEmail = data.user.altEmail || '';
editForm.phone = data.user.phone || '';
});

let isSubmitting = $state(false);

const handleSave: SubmitFunction = () => {
Expand Down
6 changes: 3 additions & 3 deletions programmerbar-web/src/worker-configuration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7249,8 +7249,7 @@ interface IncomingRequestCfPropertiesBotManagement {
*/
clientTrustScore: number;
}
interface IncomingRequestCfPropertiesBotManagementEnterprise
extends IncomingRequestCfPropertiesBotManagement {
interface IncomingRequestCfPropertiesBotManagementEnterprise extends IncomingRequestCfPropertiesBotManagement {
/**
* Results of Cloudflare's Bot Management analysis
*/
Expand Down Expand Up @@ -8682,7 +8681,8 @@ declare namespace CloudflareWorkersModule {
export abstract class WorkflowEntrypoint<
Env = unknown,
T extends Rpc.Serializable<T> | unknown = unknown
> implements Rpc.WorkflowEntrypointBranded
>
implements Rpc.WorkflowEntrypointBranded
{
[Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never;
protected ctx: ExecutionContext;
Expand Down
Loading