2
0
forked from jmug/cactoide

fix: windows not defined in SSR

This commit is contained in:
Levente Orban
2025-09-24 20:18:52 +02:00
parent b64d48a933
commit a59bc3601c

View File

@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores'; import { page } from '$app/stores';
import { browser } from '$app/environment';
import type { Event, RSVP } from '$lib/types'; import type { Event, RSVP } from '$lib/types';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { enhance } from '$app/forms'; import { enhance } from '$app/forms';
@@ -28,13 +29,13 @@
$: currentUserId = data.userId; $: currentUserId = data.userId;
// Create calendar event object when event data changes // Create calendar event object when event data changes
$: if (event) { $: if (event && browser) {
calendarEvent = { calendarEvent = {
name: event.name, name: event.name,
date: event.date, date: event.date,
time: event.time, time: event.time,
location: event.location, location: event.location,
url: `${window.location.origin}/event/${eventId}` url: `${$page.url.origin}/event/${eventId}`
}; };
} }
@@ -56,13 +57,15 @@
const eventId = $page.params.id || ''; const eventId = $page.params.id || '';
const copyEventLink = () => { const copyEventLink = () => {
const url = `${window.location.origin}/event/${eventId}`; if (browser) {
const url = `${$page.url.origin}/event/${eventId}`;
navigator.clipboard.writeText(url).then(() => { navigator.clipboard.writeText(url).then(() => {
success = 'Event link copied to clipboard!'; success = 'Event link copied to clipboard!';
setTimeout(() => { setTimeout(() => {
success = ''; success = '';
}, 3000); }, 3000);
}); });
}
}; };
const clearMessages = () => { const clearMessages = () => {
@@ -408,12 +411,12 @@
</div> </div>
<!-- Calendar Modal --> <!-- Calendar Modal -->
{#if calendarEvent} {#if calendarEvent && browser}
<CalendarModal <CalendarModal
bind:isOpen={showCalendarModal} bind:isOpen={showCalendarModal}
event={calendarEvent} event={calendarEvent}
{eventId} {eventId}
baseUrl={window.location.origin} baseUrl={$page.url.origin}
on:close={closeCalendarModal} on:close={closeCalendarModal}
/> />
{/if} {/if}