Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaSain committed Feb 24, 2024
1 parent 165f9e3 commit 959bb34
Show file tree
Hide file tree
Showing 17 changed files with 929 additions and 180 deletions.
733 changes: 687 additions & 46 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"lint": "next lint"
},
"dependencies": {
"@google-cloud/storage": "^7.7.0",
"@next-auth/prisma-adapter": "^1.0.7",
"@prisma/client": "^5.4.2",
"@prisma/client": "^5.6.0",
"next": "^14.0.1",
"next-auth": "^4.24.4",
"nextjs": "^0.0.3",
"react": "^18",
"react-dom": "^18",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-tailwindcss-datepicker": "^1.6.6"
},
"devDependencies": {
Expand All @@ -27,7 +28,7 @@
"postcss": "^8",
"prettier": "3.0.3",
"prettier-plugin-tailwindcss": "^0.5.6",
"prisma": "^5.4.2",
"prisma": "^5.6.0",
"tailwindcss": "^3",
"typescript": "^5"
}
Expand Down
20 changes: 10 additions & 10 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ model Contest {
id Int @id @default(autoincrement())
name String?
author String
hostedOnPlatoform Boolean?
restrictUsersOnRegion String?
restrictUsersOnGroup String?
// hostedOnPlatoform Boolean?
// restrictUsersOnRegion String?
// restrictUsersOnGroup String?
restrictUsersSchool Boolean?
restrictUsersStudents Boolean?
restrictUsersMinAge Int?
restrictUsersMaxAge Int?
restrictUsersLimit Int?
hasAward Boolean? //
// restrictUsersMinAge Int?
// restrictUsersMaxAge Int?
// restrictUsersLimit Int?
hasAward Boolean?
startDate DateTime?
endDate DateTime?
description String?
location String?
bannerURL String?
logoURL String?
regulationsURL String?
regulationsPDF Boolean?
// regulationsPDF Boolean?
Instagram String?
Facebook String?
LinkedIn String?
GitHub String?
// GitHub String?
}
97 changes: 93 additions & 4 deletions src/app/actions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,97 @@
"use server";
import prisma from "./lib/db";
import { Contest } from "./types/types";
import { Stream } from "stream";
import bucket from "./lib/storage";
import { getServerSession } from "next-auth/next";
import authOptions from "./lib/auth";
import { PrismaClient } from "@prisma/client";
import { redirect } from "next/navigation";

const prisma = new PrismaClient();
function _arrayBufferToBase64(buffer: ArrayBuffer) {
var binary = "";
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return btoa(binary);
}

async function upload(file: File, name: string, contentType: string) {
const arrayBuffer = await file.arrayBuffer();

let base64 = _arrayBufferToBase64(arrayBuffer);
var bufferStream = new Stream.PassThrough();
bufferStream.end(Buffer.from(base64, "base64"));

var uFile = bucket.file(name);
bufferStream
.pipe(
uFile.createWriteStream({
metadata: {
contentType: contentType,
},
}),
)
.on("error", function (err) {
console.log(err);
})
.on("finish", function () {
console.log("upload done");
return "sampleurl";
});
}

export async function createContest(formData: FormData) {
console.log(formData);
//return prisma.contest.create({ data: formData });
prisma.$connect();
const session = await getServerSession(authOptions);
if (!session) {
throw Error("user must be authentificated!");
}

const mail = session.user?.email || "noMail";
const logo = formData.get("logo") as File;
const pdf = formData.get("regulations") as File;
const name = formData.get("name") as string;
await upload(logo, name + "logo", "image/jpeg");
await upload(pdf, name + "regulations", "application/pdf");
await prisma.contest
.create({
data: {
name: name,
author: mail,
hasAward: false,
restrictUsersSchool: Boolean(
formData.get("restrictHighSchool") as string,
),
restrictUsersStudents: Boolean(
formData.get("restrictHighSchool") as string,
),
startDate: new Date(formData.get("startDate") as string).toISOString(),
endDate: new Date(formData.get("endDate") as string).toISOString(),
location: "",
logoURL:
"https://storage.googleapis.com/" +
process.env.BUCKET_NAME +
"/" +
name +
"logo",
regulationsURL:
"https://storage.googleapis.com/" +
process.env.BUCKET_NAME +
"/" +
name +
"regulations",
Instagram: formData.get("instagram") as string,
Facebook: formData.get("facebook") as string,
LinkedIn: formData.get("linkedIn") as string,
},
})
.then((t) => {
console.log(t);
prisma.$disconnect();
});
redirect("/");
}

export async function fetchContests(tags: Array<{ author: string }>) {}
32 changes: 23 additions & 9 deletions src/app/components/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
export default function Card() {
import prisma from "../lib/db";
import { Contest } from "../types/types";

interface Props {
contest: Contest;
}

export default async function Card(props: Props) {
const author = await prisma.user.findUnique({
where: {
email: props.contest.author,
},
});
return (
<div className="relative flex w-full flex-col overflow-hidden rounded-lg border-2 border-neutral shadow-lg">
<div className="relative flex w-full flex-col overflow-hidden rounded-lg border-2 border-neutral shadow-lg">
<img
src="/images.jpeg"
src={props.contest.logoURL}
className="absolute right-0 z-0 h-2/3 w-1/3 rounded-lg object-cover opacity-60 blur-2xl brightness-150 filter"
/>

<div className="z-20 p-4">
<div className="text text-4xl">Contestname</div>
<div className="text-xl">Organisator name</div>
<div className="z-0 p-4">
<div className="text text-2xl">{props.contest.name}</div>
<div className="text-lg">{author?.name}</div>
<div className="badge badge-neutral">Main badge</div>

<div className="flex-1"></div>
<div className="flex w-full flex-row items-end justify-end">
<div className="">Starts in 24h</div>
<div className="text-xs">
Starts on {props.contest.startDate?.toUTCString()}
</div>
<div className="flex-1"></div>
<div className="btn btn-ghost max-w-max border-2 border-neutral bg-base-100 shadow-lg">
<div className="btn btn-ghost max-w-max border-2 border-neutral bg-base-100 shadow-lg">
Info
</div>
</div>
<img
src="/images.jpeg"
src={props.contest.logoURL}
className=" mask mask-circle absolute right-[-6px] top-2 h-1/2 w-1/3 rounded-full object-cover"
/>
</div>
Expand Down
13 changes: 1 addition & 12 deletions src/app/components/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
"use client";
import { useState } from "react";
import { DateType, DateValueType } from "react-tailwindcss-datepicker";
import Explore from "./Explore";

export default function Drawer() {
const [value, setValue] = useState<DateValueType>({
startDate: new Date(),
endDate: new Date(),
});

const handleValueChange = (newValue: DateValueType) => {
console.log("newValue:", newValue);
setValue(newValue);
};

const orgs = [
{ id: "1", text: "org" },
{ id: "2", text: "org" },
Expand All @@ -27,7 +16,7 @@ export default function Drawer() {
];
return (
<>
<div className="drawer lg:drawer-open">
<div className="drawer z-[90] lg:drawer-open">
<input id="my-drawer-2" type="checkbox" className="drawer-toggle" />
<div className="drawer-content flex flex-col items-center justify-center ">
<label
Expand Down
40 changes: 7 additions & 33 deletions src/app/components/Explore.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
import prisma from "../lib/db";
import { Contest } from "../types/types";
import Card from "./Card";

export default function Explore({ data }: { data?: Array<Contest> }) {
export default async function Explore({ data }: { data?: Array<Contest> }) {
const contests = await prisma.contest.findMany();
return (
<div className="grid min-h-screen w-full flex-1 grid-cols-1 gap-2 px-2 py-2 sm:grid-cols-3 sm:pt-20">
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<Card />
<div className="grid min-h-screen w-full flex-1 grid-cols-1 grid-rows-4 gap-2 px-2 py-2 sm:grid-cols-3 sm:pt-20">
{contests.map((contest) => {
return <Card key={contest.name} contest={contest as Contest} />;
})}
</div>
);
}
6 changes: 3 additions & 3 deletions src/app/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Link from "next/link";

export default function Navbar() {
return (
<div className="navbar fixed z-[999] w-full rounded-none border-neutral bg-base-100 bg-opacity-80 backdrop-blur-xl sm:absolute sm:backdrop-blur-0 ">
<div className="navbar fixed z-[999] w-full rounded-none border-neutral bg-base-100 bg-opacity-80 backdrop-blur-xl sm:absolute sm:backdrop-blur-0 ">
<div className="navbar-start">
<Link
href="/"
Expand All @@ -14,12 +14,12 @@ export default function Navbar() {
</Link>
</div>
<div className="navbar-center">
<Link
<a
href="/explore"
className="btn btn-sm border-2 border-neutral bg-transparent shadow-md sm:btn-md"
>
explore
</Link>
</a>
</div>
<div className="navbar-end">
<UserControl />
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/UserControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async function UserControl() {
</ul>
</div>
) : (
<a href="/api/auth/signin" className="btn btn-neutral">
<a href="/api/auth/signin" className="btn btn-neutral btn-sm sm:btn-md">
Sign in
</a>
)}
Expand Down
Loading

0 comments on commit 959bb34

Please sign in to comment.