Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/instagram-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/tiktok-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 35 additions & 38 deletions src/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,54 +37,53 @@ class OldApi {
endpoint: string,
options: RequestInit,
schema: SchemaType,
includeHeaders: true,
includeHeaders: true
): Promise<{ data: ZodInfer<SchemaType>; headers: Headers }>;

async request<SchemaType extends ZodSchema>(
endpoint: string,
options: RequestInit,
schema: SchemaType,
includeHeaders?: false,
includeHeaders?: false
): Promise<ZodInfer<SchemaType>>;

async request<SchemaType extends ZodSchema>(
endpoint: string,
options: RequestInit,
schema: SchemaType,
schema: SchemaType
): Promise<ZodInfer<SchemaType>>;

async request(
endpoint: string,
options: RequestInit,
includeHeaders: true,
includeHeaders: true
): Promise<{ data: unknown; headers: Headers }>;

async request(
endpoint: string,
options?: RequestInit,
includeHeaders?: false,
includeHeaders?: false
): Promise<unknown>;

async request<RequestedType>(
endpoint: string,
options?: RequestInit,
includeHeaders?: boolean,
includeHeaders?: boolean
): Promise<RequestedType & { headers: never }>;

async request<RequestedType>(
endpoint: string,
options?: RequestInit,
includeHeaders?: true,
includeHeaders?: true
): Promise<RequestedType & { headers: Headers }>;

async request<SchemaType extends ZodSchema>(
endpoint: string,
options: RequestInit = {},
schemaOrIncludeHeaders?: SchemaType | boolean,
includeHeadersFlag?: boolean,
includeHeadersFlag?: boolean
): Promise<unknown> {
const url = new URL(endpoint, this.baseUrl);
console.log(url);
const controller = new AbortController();

let schema: SchemaType | undefined;
Expand Down Expand Up @@ -114,7 +113,6 @@ class OldApi {

try {
const response = await this.fetch(url.href, mergedOptions);
console.log(response);

if (!response.ok) {
throw await ApiError.fromResponse(response.clone());
Expand All @@ -125,7 +123,7 @@ class OldApi {
throw new ApiError(
`Non-JSON response from ${url.href}`,
500,
"Invalid Content-Type",
"Invalid Content-Type"
);
}

Expand All @@ -139,7 +137,7 @@ class OldApi {
if (!parseResult.success) {
throw new ValidationError(
`Response validation failed for ${url.href}`,
parseResult.error.issues,
parseResult.error.issues
);
}
parsedData = parseResult.data;
Expand All @@ -154,7 +152,7 @@ class OldApi {
throw new ApiError(
`Invalid response structure from ${url.href}`,
500,
"Missing 'data' property in response",
"Missing 'data' property in response"
);
} catch (error) {
if (error instanceof ApiError || error instanceof ValidationError) {
Expand All @@ -172,7 +170,7 @@ class OldApi {
"Unknown error occurred",
0,
"UNKNOWN_ERROR",
String(error),
String(error)
);
} finally {
controller.abort();
Expand All @@ -182,55 +180,54 @@ class OldApi {
async get<T>(
endpoint: string,
schema?: ZodSchema<T>,
options?: RequestInit,
options?: RequestInit
): Promise<T>;

async get<T>(
endpoint: string,
options?: RequestInit,
includeHeaders?: boolean,
includeHeaders?: boolean
): Promise<T>;

async get<T>(
endpoint: string,
schemaOrOptions?: ZodSchema<T> | RequestInit,
optionsOrIncludeHeaders?: RequestInit | boolean,
optionsOrIncludeHeaders?: RequestInit | boolean
): Promise<T> {
console.log(endpoint, schemaOrOptions, optionsOrIncludeHeaders);
if (schemaOrOptions instanceof ZodSchema) {
return this.request(
endpoint,
(optionsOrIncludeHeaders as RequestInit) ?? {},
schemaOrOptions,
false,
false
);
}
return this.request(
endpoint,
(schemaOrOptions as RequestInit) ?? {},
(optionsOrIncludeHeaders as boolean) ?? false,
(optionsOrIncludeHeaders as boolean) ?? false
);
}

async post<T>(
endpoint: string,
body: unknown,
schema?: ZodSchema<T>,
options?: RequestInit,
options?: RequestInit
): Promise<T>;

async post<T>(
endpoint: string,
body: unknown,
options?: RequestInit,
includeHeaders?: true,
includeHeaders?: true
): Promise<T & { headers: Headers }>;

async post<T>(
endpoint: string,
body: unknown,
schemaOrOptions?: ZodSchema<T> | RequestInit,
optionsOrIncludeHeaders?: RequestInit | boolean,
optionsOrIncludeHeaders?: RequestInit | boolean
): Promise<T> {
const mergedOptions: RequestInit = {
method: "POST",
Expand All @@ -242,35 +239,35 @@ class OldApi {
endpoint,
{ ...mergedOptions, ...(optionsOrIncludeHeaders as RequestInit) },
schemaOrOptions,
false,
false
);
}
return this.request(
endpoint,
{ ...mergedOptions, ...(schemaOrOptions as RequestInit) },
(optionsOrIncludeHeaders as boolean) ?? false,
(optionsOrIncludeHeaders as boolean) ?? false
);
}

async put<T>(
endpoint: string,
body: unknown,
schema?: ZodSchema<T>,
options?: RequestInit,
options?: RequestInit
): Promise<T>;

async put<T>(
endpoint: string,
body: unknown,
options?: RequestInit,
includeHeaders?: boolean,
includeHeaders?: boolean
): Promise<T>;

async put<T>(
endpoint: string,
body: unknown,
schemaOrOptions?: ZodSchema<T> | RequestInit,
optionsOrIncludeHeaders?: RequestInit | boolean,
optionsOrIncludeHeaders?: RequestInit | boolean
): Promise<T> {
const mergedOptions: RequestInit = {
method: "PUT",
Expand All @@ -282,58 +279,58 @@ class OldApi {
endpoint,
{ ...mergedOptions, ...(optionsOrIncludeHeaders as RequestInit) },
schemaOrOptions,
false,
false
);
}
return this.request(
endpoint,
{ ...mergedOptions, ...(schemaOrOptions as RequestInit) },
(optionsOrIncludeHeaders as boolean) ?? false,
(optionsOrIncludeHeaders as boolean) ?? false
);
}

async delete<T>(
endpoint: string,
schema?: ZodSchema<T>,
options?: RequestInit,
options?: RequestInit
): Promise<T>;

async delete<T>(
endpoint: string,
options?: RequestInit,
includeHeaders?: boolean,
includeHeaders?: boolean
): Promise<T>;

async delete<T>(
endpoint: string,
schemaOrOptions?: ZodSchema<T> | RequestInit,
optionsOrIncludeHeaders?: RequestInit | boolean,
optionsOrIncludeHeaders?: RequestInit | boolean
): Promise<T> {
if (schemaOrOptions instanceof ZodSchema) {
return this.request(
endpoint,
(optionsOrIncludeHeaders as RequestInit) ?? {},
schemaOrOptions,
false,
false
);
}
return this.request(
endpoint,
(schemaOrOptions as RequestInit) ?? {},
(optionsOrIncludeHeaders as boolean) ?? false,
(optionsOrIncludeHeaders as boolean) ?? false
);
}

private cleanHeaders(
headers: Record<string, unknown>,
headers: Record<string, unknown>
): Record<string, string> {
return Object.fromEntries(
Object.entries(headers)
.filter(([_, value]) => value !== undefined && value !== null)
.map(([key, value]) => [
key,
String(value as NonNullable<typeof value>),
]),
])
);
}
}
Expand All @@ -342,5 +339,5 @@ if (typeof window === "undefined" && !process.env.BACKEND_URL) {
throw new Error("Backend URL not set (server-side)");
}
export const API = new OldApi(
process.env.BACKEND_URL || "https://api.flave.ee",
process.env.BACKEND_URL || "https://api.flave.ee"
);
1 change: 0 additions & 1 deletion src/app/(pages)/(protected)/(user)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LogoutButton } from "./_components/logout";

export default async function ProfilePage() {
const user = await getCurrentUser();
console.log("profile:", user);
if (!user) {
return <h1 className="text-3xl">User not found</h1>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(pages)/(public)/(home)/components/categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MarqueeItem: React.FC<{ text: string; src: string }> = ({
<div className="relative aspect-square w-full overflow-hidden golden-circle rounded-full">
<Image src={src} alt={text || "Category image"} fill quality={95} />
</div>
<h5 className="uppercase truncate max-w-[90%]">{text}</h5>
<h5 className="uppercase truncate max-w-[90%]">#{text}</h5>
</div>
);

Expand Down
18 changes: 17 additions & 1 deletion src/app/(pages)/(public)/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Button, RecipeDisplayBlock } from "@/components";
import { Button, Image, RecipeDisplayBlock } from "@/components";
// import { fetchRecipes } from "@/util";

import { CategoryMarquee, Hero } from "./components";
import { ReviewsList } from "./components/reviews";
import Link from "next/link";

export default async function Home() {
return (
Expand Down Expand Up @@ -63,6 +64,21 @@ export default async function Home() {
<div className="aspect-[720/660] bg-cover bg-no-repeat home-food-collage-for-hero-bg" />
</section>
<ReviewsList />
<section className="w-full flex gap-20 items=center justify-center p-20 pb-40">
{[
["/tiktok-card.png", "#"],
["/instagram-card.png", "https://www.instagram.com/flavedotee/"],
].map((social, index) => (
<Link key={index} href={social[1] || "#"}>
<Image
src={social[0] || ""}
alt={social[0] || "Social image"}
quality={100}
/>
</Link>
))}
</section>

{/* <FAQBlock /> */}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/(pages)/(public)/browse/_components/marquee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MarqueeItem: React.FC<{ text: string; src: string }> = ({
<div className="relative aspect-square w-full overflow-hidden golden-circle rounded-full">
<Image src={src} alt={text || "Category image"} fill quality={95} />
</div>
<h5 className="uppercase truncate max-w-[90%] text-white">{text}</h5>
<h5 className="uppercase truncate max-w-[90%] text-white">#{text}</h5>
</div>
);

Expand Down
1 change: 0 additions & 1 deletion src/app/(pages)/(public)/browse/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { validateSession } from "@/context/auth/actions";

export default async function Browse() {
const isLoggedIn = await validateSession();
console.log("isLoggedIn", isLoggedIn);
return (
<>
<Hero />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Creator: React.FC<Partial<User>> = ({
as="link"
href={`/users/${_id}`}
icon={<ArrowRight className="order-1 stroke-black" />}
className="bg-foreground outline-0 text-black"
className="bg-white outline-0 text-black"
>
View profile
</Button>
Expand Down
6 changes: 2 additions & 4 deletions src/app/(pages)/(public)/recipes/[_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ function LoadingFallback() {

const RecipeContent = async ({ _id }: { _id: string }) => {
const recipe = await API.get<Recipe>("recipes/" + _id);
console.log(recipe);
const [start, end] = getDurationBucket(recipe.cookingDuration);

const cookingDuration = `${start}-${end} mins`;
console.log(recipe.src);
return (
<>
<section className="flex gap-10 w-full aspect-section-lg p-20 -mt-10 recipe-details-man-decal-bg">
Expand All @@ -97,7 +95,7 @@ const RecipeContent = async ({ _id }: { _id: string }) => {
{recipe.tags.map(({ _id, value }) => (
<Link
key={_id}
href={`/search?tags=${value.toLowerCase()}`}
href={`/recipes?tags=${value.toLowerCase()}`}
className="no-underline"
>
<Tag>{value}</Tag>
Expand Down Expand Up @@ -207,7 +205,7 @@ const RecipeContent = async ({ _id }: { _id: string }) => {
<ol className="flex flex-col gap-4 pl-0">
{recipe.instructions.map((instruction, idx) => (
<li key={idx} className="flex items-center gap-2.5">
<div className="flex-shrink-0 flex items-center justify-center aspect-square golden-circle w-5 h-5 rounded-full bg-black text-white text-sm font-medium">
<div className="flex-shrink-0 flex items-center justify-center aspect-square w-5 h-5 rounded-full bg-black text-white text-sm font-medium">
{idx + 1}
</div>

Expand Down
Loading
Loading