Skip to content

Commit

Permalink
feat: add subscribe calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Lilleby authored and Anton Lilleby committed Jan 31, 2025
1 parent 2d9dfe9 commit 47af002
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
7 changes: 7 additions & 0 deletions app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ APP_SECRET=""
APP_API_TOKEN=""
CRON_SECRET=""

PUBLIC_CAPRA_BASE_URL=""
PUBLIC_FRYDE_BASE_URL=""
PUBLIC_LIFLIG_BASE_URL=""

PUBLIC_SANITY_PROJECT_ID=""
PUBLIC_SANITY_DATASET=""
PUBLIC_SANITY_API_VERSION=""
PUBLIC_SANITY_STUDIO_URL=""
SANITY_API_READ_TOKEN=""
SANITY_API_WRITE_TOKEN=""

AUTH_TRUST_HOST=""
AUTH_SECRET=""
Expand All @@ -23,3 +28,5 @@ SUPABASE_CONNECTION_STRING=""
SMTP_HOST=""
SMTP_AUTH_USER=""
SMTP_AUTH_KEY=""

SLACK_HOOK=""
2 changes: 1 addition & 1 deletion app/src/components/shared/SignedInDesktopMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</Button>
<Button
color="alternative"
class="hidden h-9 rounded-2xl border-[#999] p-2.5"
class="h-9 rounded-2xl border-[#999] p-2.5"
target="_blank"
rel="noopener noreferrer"
href={subscribeLink}
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/shared/SignedInMobileMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</Button>
<Button
color="alternative"
class="hidden h-9 w-32 border-[#999]"
class="h-9 w-32 border-[#999]"
pill
target="_blank"
rel="noopener noreferrer"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PUBLIC_APP_DEFAULT_BASE_URL } from "$env/static/public";
import { PUBLIC_APP_BASE_URL } from "$env/static/public";
import { SLACK_HOOK } from "$env/static/private";
import { urlFor } from "$lib/sanity/image";
import type { Event } from "$models/sanity.model";
Expand All @@ -15,7 +15,7 @@ export const sendSlackNotification = async ({
if (process.env.NODE_ENV === "development") return;

const imageUrl = image ? urlFor(image).width(400).url() : null;
const eventUrl = `${PUBLIC_APP_DEFAULT_BASE_URL}/event/${id}`;
const eventUrl = `${PUBLIC_APP_BASE_URL}/event/${id}`;

const startDate = new Date(start).toLocaleDateString("nb-NO", {
hour: "2-digit",
Expand Down
24 changes: 18 additions & 6 deletions app/src/routes/api/subscribe/+server.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import { PUBLIC_APP_DEFAULT_BASE_URL } from "$env/static/public";
import { PUBLIC_APP_BASE_URL } from "$env/static/public";
import { getFutureEvents } from "$lib/server/sanity/queries";
import type { RequestHandler } from "@sveltejs/kit";
import ical, { ICalCalendarMethod, type ICalEventData } from "ical-generator";
import ical, {
ICalCalendarMethod,
ICalEventTransparency,
type ICalEventData,
} from "ical-generator";

export const GET: RequestHandler = async () => {
try {
const events = await getFutureEvents();
const calendar = ical({ name: "Skjer", method: ICalCalendarMethod.REQUEST });
const calendar = ical({ name: "Skjer", method: ICalCalendarMethod.PUBLISH });

events.forEach(
({ _id: id, title: summary, summary: description, start, end, place: location }) => {
const url = `${PUBLIC_APP_DEFAULT_BASE_URL}/event/${id}`;
({
_id: id,
title: summary,
summary: description = "",
place: location = "",
start,
end,
}) => {
const url = `${PUBLIC_APP_BASE_URL}/event/${id}`;
const eventData: ICalEventData = {
id,
summary,
description: `${description ?? ""} ${url}`,
description: `${url} ${description}`,
location,
start,
end,
url,
transparency: ICalEventTransparency.TRANSPARENT,
};
calendar.createEvent(eventData);
}
Expand Down

0 comments on commit 47af002

Please sign in to comment.