Skip to content

Commit

Permalink
add date to ticket page
Browse files Browse the repository at this point in the history
  • Loading branch information
quick007 committed Feb 16, 2024
1 parent ab4dfad commit a080d7a
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 50 deletions.
6 changes: 5 additions & 1 deletion components/buttons/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ const Button = ({
{icon}
</CTA>
</Wrapper>
<div className={`absolute w-32 bg-white border border-gray-300 rounded-md text-center shadow-xl ${labelOnTop ? "bottom-12" : "top-12"} select-none scale-95 opacity-0 peer-hover:scale-100 peer-hover:opacity-100 transition z-50`}>
<div
className={`absolute w-32 bg-white border border-gray-300 rounded-md text-center shadow-xl ${
labelOnTop ? "bottom-12" : "top-12"
} select-none scale-95 opacity-0 peer-hover:scale-100 peer-hover:opacity-100 transition z-50`}
>
{label}
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions components/faq/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export const faqs: FAQ[] = [
},
{
q: "How do timezones work for events without a time?",
a: "Events without a specific time of day set will always have the same date, regardless of timezone. Note that the event settings page may display an incorrect date if you're in a different timezone than when the date was selected."
},
a: "Events without a specific time of day set will always have the same date, regardless of timezone. Note that the event settings page may display an incorrect date if you're in a different timezone than when the date was selected.",
},
{
q: "How do timezones work for events with a time?",
a: "Events with a time of day set will always convert to the user's timezone that is viewing the event. The event settings page will do it's best to convert to the user's local timezone."
}
a: "Events with a time of day set will always convert to the user's timezone that is viewing the event. The event settings page will do it's best to convert to the user's local timezone.",
},
];

export interface FAQ {
Expand Down
8 changes: 5 additions & 3 deletions islands/components/pickers/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ export default function Dropdown({

return (
<>
{option.link ? <a href={option.link}>{btn}</a> : btn}
{option.breakBelow && <div class="h-0.5 rounded-full bg-gray-200 px-2"/> }
{option.link ? <a href={option.link}>{btn}</a> : btn}
{option.breakBelow && (
<div class="h-0.5 rounded-full bg-gray-200 px-2" />
)}
</>
)
);
})}
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion islands/components/pieces/ticket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
import { qrcode } from "https://deno.land/x/[email protected]/mod.ts";
import { QR } from "@/components/svgs/qr.tsx";
import { ClientDate } from "@/islands/events/viewing/dates.tsx";

export default function Ticket({
showTime,
Expand Down Expand Up @@ -51,7 +52,11 @@ export default function Ticket({
<div class="grid gap-2 mt-4 font-medium ">
<div>
<div class="bg-gray-100 border px-1.5 rounded-md text-center">
{fmtDate(new Date(showTime.startDate!))}
{showTime.startTime ? (
fmtDate(new Date(showTime.startDate))
) : (
<ClientDate date={showTime.startDate} />
)}
</div>
</div>
<div class="flex justify-center">
Expand Down
4 changes: 3 additions & 1 deletion islands/events/editing/showtimesettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default function ShowTimeSettings({
const res = await fetch("/api/events/edit", {
body: JSON.stringify({
eventID,
newEventData: { showTimes: fixDate(currentState.value) } as Partial<Event>,
newEventData: {
showTimes: fixDate(currentState.value),
} as Partial<Event>,
}),
method: "POST",
});
Expand Down
5 changes: 2 additions & 3 deletions islands/events/viewing/dates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import { fmtDate } from "@/utils/dates.ts";

// bit of a hack, bassiclly just takes the date, chops off the timezone, and gets the date wherever the user is
export const ClientDate = ({ date }: { date: string }) => (
<>{fmtDate(new Date(date.split("GMT")[0]))}</>
)

<>{fmtDate(new Date(date.split("GMT")[0]))}</>
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
],
"scripts": {
"dev": "email dev",
"export": "email export"
"export": "email export",
"ionic:serve": "npm run dev"
},
"dependencies": {
"@react-email/components": "^0.0.12",
Expand Down
6 changes: 3 additions & 3 deletions routes/events/(pages)/attending/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineLayout, RouteContext } from "$fresh/server.ts";
import { Event, getUser, kv, Ticket, User } from "@/utils/db/kv.ts";
import { Event, getUser, kv, ShowTime, Ticket, User } from "@/utils/db/kv.ts";

export default defineLayout(
async (req: Request, ctx: RouteContext<void, TicketContext>) => {
Expand Down Expand Up @@ -36,7 +36,7 @@ export default defineLayout(

return {
id: id as string,
date: new Date(showTime.startDate),
time: showTime,
event: event,
};
});
Expand Down Expand Up @@ -77,7 +77,7 @@ export interface TicketContext {
tickets: {
id: string;
event: Event;
date: Date;
time: ShowTime;
}[];
user: User;
};
Expand Down
26 changes: 23 additions & 3 deletions routes/events/(pages)/attending/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Scanner from "@/islands/events/scanning.tsx";
import { badEventRequest } from "@/routes/events/[id]/_layout.tsx";
import ImagekitImage from "@/components/imagekitimg.tsx";
import CTA from "@/components/buttons/cta.tsx";
import { fmtDate } from "@/utils/dates.ts";
import { fmtTime } from "@/utils/dates.ts";
import { ClientDate } from "@/islands/events/viewing/dates.tsx";

export default defineRoute((req, ctx: RouteContext<void, TicketContext>) => {
const { tickets, user } = ctx.state.data;
Expand All @@ -17,7 +20,20 @@ export default defineRoute((req, ctx: RouteContext<void, TicketContext>) => {
<main className="px-4 max-w-screen-md w-full mx-auto flex flex-col gap-8 grow mb-10">
<div class="grid md:grid-cols-2 gap-4">
{tickets.map((ticket) => (
<div class="rounded-md border flex flex-col p-3">
<div class="rounded-md border flex flex-col p-4">
<div class="rounded-md border bg-gray-100 px-1 mb-4 font-medium mx-auto">
{ticket.time.startTime ? (
<>
{fmtDate(new Date(ticket.time.startDate))}
<span class="lowercase">
{ticket.time.startTime &&
` at ${fmtTime(new Date(ticket.time.startTime))}`}
</span>
</>
) : (
<ClientDate date={ticket.time.startDate} />
)}
</div>
<div class="relative">
{ticket.event.banner.path ? (
<ImagekitImage
Expand All @@ -38,8 +54,12 @@ export default defineRoute((req, ctx: RouteContext<void, TicketContext>) => {
)}
</div>
<div class=" mt-4 flex flex-col items-center grow">
<h3 class="text-xl font-bold text-center line-clamp-1 max-w-max">{ticket.event.name}</h3>
<p class="line-clamp-3 text-sm text-pretty text-center mt-2 mb-4">{ticket.event.summary}</p>
<h3 class="text-xl font-bold text-center line-clamp-1 max-w-max">
{ticket.event.name}
</h3>
<p class="line-clamp-3 text-sm text-pretty text-center mt-2 mb-4">
{ticket.event.summary}
</p>
<CTA btnType="secondary" btnSize="sm" className="mt-auto">
View Ticket
</CTA>
Expand Down
5 changes: 4 additions & 1 deletion utils/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ export const fmtHour = (date: Date) => hourFmt.format(date);
export const fmtTime = (date: Date) => timeFmt.format(date);
// not an ideal solution
export const getTimeZone = (date: Date) =>
date.toString().split("(")[1].slice(undefined, date.toString().split("(")[1].length - 1);
date
.toString()
.split("(")[1]
.slice(undefined, date.toString().split("(")[1].length - 1);
1 change: 1 addition & 0 deletions utils/db/kv.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Event {
published: boolean;
}

// known to users as Event Times
export interface ShowTime {
startDate: string;
startTime?: string;
Expand Down
35 changes: 18 additions & 17 deletions utils/event/fixDate.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { ShowTime } from "@/utils/db/kv.ts";

export const fixDate = (showTimes: ShowTime[]) => showTimes.map((showTime) => {
if (!showTime.startTime) return showTime;
const date = new Date(showTime.startDate);
const time = new Date(showTime.startTime);
export const fixDate = (showTimes: ShowTime[]) =>
showTimes.map((showTime) => {
if (!showTime.startTime) return showTime;
const date = new Date(showTime.startDate);
const time = new Date(showTime.startTime);

if (time) {
date.setHours(time.getHours());
date.setMinutes(time.getMinutes());
} else {
// remove the hours and just display as normal if user doesn't add a start date
date.setHours(0);
date.setMinutes(0);
}
if (time) {
date.setHours(time.getHours());
date.setMinutes(time.getMinutes());
} else {
// remove the hours and just display as normal if user doesn't add a start date
date.setHours(0);
date.setMinutes(0);
}

return {
...showTime,
startDate: date.toString(),
};
})
return {
...showTime,
startDate: date.toString(),
};
});
24 changes: 12 additions & 12 deletions utils/imagekit/URL.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import imagekit from "@/utils/imagekit/index.ts";

export const getURL = (width: number, path: string) =>
["png", "webp"].map((fmt) =>
imagekit!.url({
path,
transformation: [
{
width: width.toString(),
quality: "85",
format: fmt,
},
],
}),
);
["png", "webp"].map((fmt) =>
imagekit!.url({
path,
transformation: [
{
width: width.toString(),
quality: "85",
format: fmt,
},
],
}),
);

0 comments on commit a080d7a

Please sign in to comment.