Skip to content

Commit

Permalink
update example env + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
quick007 committed Jan 16, 2024
1 parent c3bbfd8 commit 3305e42
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 62 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ ALLOWED_EMAILS=["[email protected]","[email protected]"]
# To disable Imagekit delete these 3 variables
IMAGEKIT_PUBLIC_KEY=<imagekit public key> (i.e. "public_...")
IMAGEKIT_PRIVATE_KEY=<imagekit private key> (i.e. "private_...")
IMAGEKIT_URL_ENDPOINT=<imagekit url> (i.e. "https://ik.imagekit.io/...")
IMAGEKIT_URL_ENDPOINT=<imagekit url> (i.e. "https://ik.imagekit.io/...")
AWS_ACCESS_KEY_ID=....
AWS_SECRET_ACCESS_KEY=....
5 changes: 2 additions & 3 deletions components/layout/navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { UserPartial } from "@/utils/db/kv.ts";
import NavbarDropDown from "@/islands/components/peices/navDropDown.tsx";

const Navbar = ({user}: {user: UserPartial | undefined}) => {
const Navbar = ({ user }: { user: UserPartial | undefined }) => {
const loggedIn = true;

return (
<div class="flex sticky top-0 bg-white h-14 z-30">
{user &&
<NavbarDropDown user={user} /> }
{user && <NavbarDropDown user={user} />}
<div
className={`fixed left-0 right-0 top-0 flex justify-center items-center h-14`}
>
Expand Down
2 changes: 1 addition & 1 deletion components/svgs/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const NotFound = () => (
viewBox="0 0 1018 753"
fill="none"
xmlns="http://www.w3.org/2000/svg"
class="max-h-[50vh] max-w-[80vw]"
class="max-h-[50vh] max-w-[80vw]"
>
<g clip-path="url(#clip0_1398_2)">
<path
Expand Down
6 changes: 5 additions & 1 deletion islands/components/peices/navDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const NavbarDropDown = ({ user }: { user: UserPartial }) => {
},
]}
>
<button class={`${open.value ? "bg-gray-200" : "hover:bg-gray-200"} flex p-1 md:px-3 md:py-1.5 items-center transition md:rounded-md rounded-full`}>
<button
class={`${
open.value ? "bg-gray-200" : "hover:bg-gray-200"
} flex p-1 md:px-3 md:py-1.5 items-center transition md:rounded-md rounded-full`}
>
<p class="font-medium hidden md:block max-w-sm truncate">
{user.email.split("@")[0]}
</p>
Expand Down
31 changes: 16 additions & 15 deletions islands/events/scanning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default function Scanner({
const currentTicket = useSignal<
| { code: string; status: "invalid" | "loading"; ticketData: null }
| {
code: string;
status: "used" | "valid" | "inactive";
ticketData: Ticket;
}
code: string;
status: "used" | "valid" | "inactive";
ticketData: Ticket;
}
| null
>(null);
const cameraIds = useSignal<MediaDeviceInfo[]>([]);
Expand Down Expand Up @@ -63,8 +63,9 @@ export default function Scanner({

currentCamera.value = devices.id;

const videoDevices = (await navigator.mediaDevices.enumerateDevices())
.filter((d) => d.kind == "videoinput");
const videoDevices = (
await navigator.mediaDevices.enumerateDevices()
).filter((d) => d.kind == "videoinput");

cameraIds.value = videoDevices;

Expand All @@ -87,7 +88,7 @@ export default function Scanner({

video.onerror = (e) => {
console.error(e);
}
};

video.onloadedmetadata = () => {
video.play();
Expand All @@ -98,10 +99,10 @@ export default function Scanner({
string,
| { status: "loading" | "invalid"; checkedAt: number }
| {
status: "valid" | "used" | "inactive";
ticketData: Ticket;
checkedAt: number;
}
status: "valid" | "used" | "inactive";
ticketData: Ticket;
checkedAt: number;
}
> = new Map();

setInterval(() => {
Expand Down Expand Up @@ -133,7 +134,7 @@ export default function Scanner({
currentCameraBeingRendered = deviceId;

video.srcObject = devices;
}
};

const fetchCodeInfo = async (code: string) => {
const res = await fetch(`/api/events/fetch`, {
Expand Down Expand Up @@ -173,10 +174,10 @@ export default function Scanner({
for (const code of codes) {
if (
code.boundingBox.width * code.boundingBox.height >
largestCode.size
largestCode.size
) {
largestCode.size = code.boundingBox.width *
code.boundingBox.height;
largestCode.size =
code.boundingBox.width * code.boundingBox.height;
largestCode.code = code;
}
}
Expand Down
7 changes: 3 additions & 4 deletions islands/events/viewing/selectShowTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const SelectShowTime = ({
>
<h3 class="font-bold text-lg mb-2">Change</h3>
<div class="grid gap-2">
{/* All event times button */}
{all && (
{/* All event times button */}
{all && (
<button
onClick={() =>
typeof showTime == "string"
Expand All @@ -77,7 +77,7 @@ const SelectShowTime = ({
<p class="flex">All Event Times</p>
</button>
)}

{showTimes.map((time) => (
<button
onClick={() =>
Expand All @@ -101,7 +101,6 @@ const SelectShowTime = ({
</p>
</button>
))}

</div>
<button
type="button"
Expand Down
2 changes: 1 addition & 1 deletion routes/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Partial } from "$fresh/runtime.ts";
import { getUser } from "@/utils/db/kv.ts";

export default defineLayout(async (req, { Component }) => {
const user = await getUser(req)
const user = await getUser(req);

return (
<div className="min-h-screen flex flex-col">
Expand Down
9 changes: 6 additions & 3 deletions routes/api/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export const handler: Handlers<{ email: string; otp: string }> = {
html: true,
});
} catch (err) {
console.error(err)
console.error(err);
return new Response(
JSON.stringify({ error: "An error occured while sending the confirmation email. Please try again." }),
JSON.stringify({
error:
"An error occured while sending the confirmation email. Please try again.",
}),
{
status: 400,
},
Expand Down Expand Up @@ -125,7 +128,7 @@ export const handler: Handlers<{ email: string; otp: string }> = {
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30),
value: userAuthToken!,
path: "/",
sameSite: "Strict"
sameSite: "Strict",
});

return resp;
Expand Down
19 changes: 11 additions & 8 deletions routes/events/[id]/(no-layout)/tickets/[tixid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export default defineRoute(
const ticketID = ctx.params.tixid;
const url = new URL(req.url);
const queryValue = url.searchParams.get("s");

if (!user || user.role == undefined || user.role > 2) {
return badEventRequest;
}

const sid = getShowtimeID(user?.data, eventID, ticketID)
const sid = getShowtimeID(user?.data, eventID, ticketID);
const showTimeID: string | undefined = queryValue || sid;
const id = `${eventID}_${showTimeID}_${ticketID}`;

Expand All @@ -33,7 +33,9 @@ export default defineRoute(
return (
<>
<Head>
<title>{ticket.value.firstName}'s ticket - {event.name} - Events</title>
<title>
{ticket.value.firstName}'s ticket - {event.name} - Events
</title>
<meta property="og:type" content="website" />
<meta
property="og:url"
Expand Down Expand Up @@ -64,11 +66,12 @@ export default defineRoute(
<main className="px-4 max-w-screen-md w-full mx-auto flex flex-col gap-8 grow mb-10 items-center mt-10 md:mt-24">
<h1 class="font-extrabold text-2xl text-center">Your Ticket</h1>
<div class="rounded-md px-6 pt-2 pb-4 border-2 border-theme-normal text-center">
<TicketComponent
id={id}
showTime={event.showTimes.find((s) => s.id == showTimeID)!}
tickets={1}
/></div>
<TicketComponent
id={id}
showTime={event.showTimes.find((s) => s.id == showTimeID)!}
tickets={1}
/>
</div>
</main>
<Footer includeWave={false} />
</div>
Expand Down
8 changes: 5 additions & 3 deletions routes/events/[id]/tickets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ export default defineRoute(
const request = ["ticket", eventID];
if (showTimeID !== "0") request.push(showTimeID);
const pageSize = 1;
const tix = kv.list<Ticket>({ prefix: request, }, { limit: pageSize, cursor: cursor || undefined });
const tix = kv.list<Ticket>(
{ prefix: request },
{ limit: pageSize, cursor: cursor || undefined },
);
let tickets: Deno.KvEntry<Ticket>[] = [];
for await (const ticket of tix) {
tickets.push(ticket);
}

console.log(tix.cursor);
console.log(await tix.next())

console.log(await tix.next());

if (queryValue) {
tickets = tickets.filter(
Expand Down
3 changes: 1 addition & 2 deletions static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

@font-face {
font-family: "Inter";
src:
url("/inter.ttf")
src: url("/inter.ttf");
}

.test {
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
content: ["{routes,islands,components}/**/*.{ts,tsx}"],
theme: {
fontFamily: {
"sans": ["Inter", "Comic Sans MS"]
sans: ["Inter", "Comic Sans MS"],
},
extend: {
colors: {
Expand Down
2 changes: 1 addition & 1 deletion utils/db/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const getUserEmailCode = async (
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30),
value: user.value.authToken,
path: "/",
sameSite: "Strict"
sameSite: "Strict",
});

return user.value;
Expand Down
40 changes: 22 additions & 18 deletions utils/email/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,30 @@ export const sesClient = new SESClient({
},
});

export const sendEmail = async (to: string[], subject: string, message: {content: string, html: boolean}) => {
export const sendEmail = async (
to: string[],
subject: string,
message: { content: string; html: boolean },
) => {
const params: SendEmailRequest = {
Source: `"Events" <[email protected]>`,
Destination: {
ToAddresses: to
},
Message: {
/* required */
Body: {
/* required */
[message.html ? "Html" : "Text"]: {
Charset: "UTF-8",
Data: message.content,
},
},
Subject: {
Charset: "UTF-8",
Data: subject,
},
},
Destination: {
ToAddresses: to,
},
Message: {
/* required */
Body: {
/* required */
[message.html ? "Html" : "Text"]: {
Charset: "UTF-8",
Data: message.content,
},
},
Subject: {
Charset: "UTF-8",
Data: subject,
},
},
};
return await sesClient.send(new SendEmailCommand(params as SendEmailRequest));
};

0 comments on commit 3305e42

Please sign in to comment.