-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
819 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
"extends": "next/core-web-vitals", | ||
"plugins": ["simple-import-sort"], | ||
"rules": { | ||
"simple-import-sort/imports": "warn", | ||
"simple-import-sort/exports": "warn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/[locale]/profile/[username]/_components/FormattedDate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useFormatter } from "next-intl"; | ||
|
||
interface Props { | ||
date: Date; | ||
} | ||
|
||
function FormatedDate({ date }: Props) { | ||
const format = useFormatter(); | ||
return ( | ||
<div className="text-sm text-gray-600 dark:text-gray-400"> | ||
{format.dateTime(date, { | ||
dateStyle: "medium", | ||
timeStyle: "short", | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
export default FormatedDate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { ChevronRightIcon } from "@radix-ui/react-icons"; | ||
import Link from "next/link"; | ||
|
||
import { EnduranceIcon, SpeedlineIcon } from "@/assets"; | ||
import HighlineImage from "@/components/HighlineImage"; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from "@/components/ui/Popover"; | ||
import { transformSecondsToTimeString } from "@/utils/helperFunctions"; | ||
import supabase from "@/utils/supabase-server"; | ||
|
||
import FormattedDate from "./FormattedDate"; | ||
|
||
interface Props { | ||
username: string; | ||
} | ||
|
||
async function LastWalks({ username }: Props) { | ||
const { data: entries } = await supabase | ||
.from("entry") | ||
.select( | ||
` | ||
*, | ||
highline (*) | ||
` | ||
) | ||
.eq("instagram", `@${username}`) | ||
.limit(5) | ||
.order("created_at", { ascending: false }); | ||
|
||
return ( | ||
<div className="max-w-screen-md rounded-xl border border-gray-200 bg-white px-2 py-4 shadow dark:divide-gray-700 dark:border-gray-700 dark:bg-gray-800"> | ||
<h3 className="text-xl font-semibold dark:text-white">Last Walks</h3> | ||
<ul className="mt-4 divide-y divide-gray-200 dark:divide-gray-700"> | ||
{entries?.map((entry) => ( | ||
<li key={entry.id} className="py-4 first:pt-0 last:pb-0"> | ||
<Popover> | ||
<PopoverTrigger className="mb-0.5 truncate text-base font-semibold leading-none text-blue-500 dark:text-blue-400"> | ||
{entry.highline?.name} | ||
</PopoverTrigger> | ||
<PopoverContent side="top" className="max-h-96 overflow-auto p-0"> | ||
<div className="relative h-12 w-full"> | ||
<HighlineImage | ||
coverImageId={entry.highline?.cover_image || null} | ||
/> | ||
</div> | ||
<div className="space-y-2 p-4"> | ||
<p>{entry.highline?.description}</p> | ||
<Link | ||
href={`/${entry.highline?.id}`} | ||
className="flex items-center font-medium text-blue-600 hover:text-blue-700 hover:underline dark:text-blue-500 dark:hover:text-blue-600" | ||
> | ||
Ver mais{" "} | ||
<ChevronRightIcon | ||
className="ml-1.5 h-3 w-3" | ||
strokeWidth={2} | ||
stroke="currentColor" | ||
/> | ||
</Link> | ||
</div> | ||
</PopoverContent> | ||
</Popover> | ||
<FormattedDate date={new Date(entry.created_at)} /> | ||
<div className="text-white-700 mb-1 flex gap-4 truncate text-sm font-normal dark:text-white"> | ||
{entry.crossing_time && ( | ||
<div className="flex items-end gap-1"> | ||
<SpeedlineIcon className="text-gray-900 dark:text-white" /> | ||
<p>{transformSecondsToTimeString(entry.crossing_time)}</p> | ||
</div> | ||
)} | ||
<div className="flex items-end gap-1"> | ||
<EnduranceIcon className="text-gray-900 dark:text-white" /> | ||
<p>{entry.distance_walked}m</p> | ||
</div> | ||
</div> | ||
<p>{entry.comment}</p> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
|
||
export default LastWalks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { cookies } from "next/headers"; | ||
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs"; | ||
|
||
import type { Database } from "@/utils/database.types"; | ||
|
||
interface Props { | ||
total_distance_walked: number; | ||
total_cadenas: number; | ||
total_full_lines: number; | ||
} | ||
async function Stats({ | ||
total_distance_walked, | ||
total_cadenas, | ||
total_full_lines, | ||
}: Props) { | ||
const displayDistanceInKM = total_distance_walked > 10000; | ||
|
||
return ( | ||
<dl className="grid max-w-screen-md grid-cols-3 gap-3 divide-x divide-gray-200 rounded-xl border border-gray-200 bg-white px-2 py-4 shadow dark:divide-gray-700 dark:border-gray-700 dark:bg-gray-800 sm:mx-auto sm:gap-8"> | ||
<div className="flex flex-col items-center justify-center"> | ||
<dt className="mb-2 text-3xl font-extrabold md:text-4xl"> | ||
{displayDistanceInKM | ||
? total_distance_walked / 1000 | ||
: total_distance_walked} | ||
<span className="text-xl font-extrabold text-gray-500 dark:text-gray-400 md:text-2xl"> | ||
{displayDistanceInKM ? "km" : "m"} | ||
</span> | ||
</dt> | ||
<dd className="font-light text-gray-500 dark:text-gray-400"> | ||
caminhados | ||
</dd> | ||
</div> | ||
<div className="flex flex-col items-center justify-center"> | ||
<dt className="mb-2 text-3xl font-extrabold md:text-4xl"> | ||
{total_cadenas} | ||
</dt> | ||
<dd className="font-light text-gray-500 dark:text-gray-400">cadenas</dd> | ||
</div> | ||
<div className="flex flex-col items-center justify-center"> | ||
<dt className="mb-2 text-3xl font-extrabold md:text-4xl"> | ||
{total_full_lines} | ||
</dt> | ||
<dd className="font-light text-gray-500 dark:text-gray-400"> | ||
full lines | ||
</dd> | ||
</div> | ||
</dl> | ||
); | ||
} | ||
|
||
export default Stats; |
26 changes: 26 additions & 0 deletions
26
app/[locale]/profile/[username]/_components/UserHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Image from "next/image"; | ||
|
||
interface Props { | ||
username: string; | ||
} | ||
|
||
function UserHeader({ username }: Props) { | ||
return ( | ||
<header className="flex max-w-screen-md gap-4 rounded-xl border border-gray-200 bg-white px-2 py-4 shadow dark:divide-gray-700 dark:border-gray-700 dark:bg-gray-800"> | ||
<Image | ||
src={"/default-profile-picture.png"} | ||
width={128} | ||
height={128} | ||
alt="Profile picture" | ||
/> | ||
<div className="space-y-3"> | ||
<h1 className="text-2xl font-semibold">@{username}</h1> | ||
<div className="rounded-lg bg-red-50 p-4 text-center text-sm text-red-500 dark:bg-red-100 dark:text-red-700"> | ||
Este usuário não é verificado | ||
</div> | ||
</div> | ||
</header> | ||
); | ||
} | ||
|
||
export default UserHeader; |
33 changes: 33 additions & 0 deletions
33
app/[locale]/profile/[username]/_components/UserNotFound.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Link from "next/link"; | ||
|
||
interface Props { | ||
username: string; | ||
} | ||
|
||
function UserHeader({ username }: Props) { | ||
return ( | ||
<section className="flex-1"> | ||
<div className="mx-auto max-w-screen-xl px-4 py-8 lg:px-6 lg:py-16"> | ||
<div className="mx-auto max-w-screen-sm text-center"> | ||
<p className="mb-4 text-3xl font-bold tracking-tight text-gray-900 dark:text-white md:text-4xl"> | ||
Usuário não existe | ||
</p> | ||
<p className="mb-4 text-lg font-light text-gray-500 dark:text-gray-400"> | ||
Não conseguimos achar nenhum usuário com o nome{" "} | ||
<span className="font-bold">@{username}</span> | ||
</p> | ||
<div className="my-4 flex justify-center gap-4"> | ||
<Link | ||
href={"/"} | ||
className="rounded-lg border border-gray-300 bg-white px-4 py-2 font-medium text-gray-900 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200 focus:ring-offset-2 dark:border-gray-500 dark:bg-gray-800 dark:fill-gray-400 dark:text-gray-400 dark:hover:border-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-700" | ||
> | ||
Voltar para a página inicial | ||
</Link> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
); | ||
} | ||
|
||
export default UserHeader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Metadata } from "next"; | ||
|
||
import supabase from "@/utils/supabase-server"; | ||
|
||
import LastWalks from "./_components/LastWalks"; | ||
import Stats from "./_components/Stats"; | ||
import UserHeader from "./_components/UserHeader"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Profile", | ||
description: "User profile", | ||
}; | ||
|
||
export default async function Profile({ | ||
params: { username }, | ||
}: { | ||
params: { username: string }; | ||
}) { | ||
const { | ||
data: { session }, | ||
} = await supabase.auth.getSession(); | ||
|
||
const { data, error } = await supabase | ||
.rpc("profile_stats", { | ||
username: `@${username}`, | ||
}) | ||
.maybeSingle(); | ||
|
||
if (!data || Object.values(data).every((value) => value === null)) { | ||
return <UserHeader username={username} />; | ||
} | ||
|
||
return ( | ||
<div className="relative mx-auto h-full w-full max-w-screen-md flex-1 space-y-4 rounded-lg px-2 pb-2 pt-0 md:space-y-6 md:pt-8"> | ||
<UserHeader username={username} /> | ||
<Stats | ||
total_cadenas={data.total_cadenas || 0} | ||
total_distance_walked={data.total_distance_walked || 0} | ||
total_full_lines={data.total_full_lines || 0} | ||
/> | ||
<LastWalks username={username} /> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.