-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete page + open graph metadata + header tweaked + static folder re…
…move for the public folder
- Loading branch information
1 parent
e98c683
commit 1f6d2c0
Showing
26 changed files
with
1,540 additions
and
1,190 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Header from "./page"; | ||
|
||
export default Header; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import MapPage from "./page"; | ||
|
||
export default MapPage; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Home from "./page"; | ||
|
||
export default Home; |
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,79 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
import { useFormState } from "react-dom"; | ||
|
||
import { deleteUser } from "@/app/_actions/deleteUser"; | ||
import { SubmitButton } from "@/components/SubmitButton"; | ||
import { ExternalLink } from "@/components/ui/ExternalLink"; | ||
import { Input } from "@/components/ui/input"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
export default function DeletePage() { | ||
const [username, setUsername] = useState<string>(""); | ||
const [isFormDisabled, setIsFormDisabled] = useState<boolean>(); | ||
const [formState, formAction] = useFormState(deleteUser, undefined); | ||
|
||
useEffect(() => { | ||
if (!formState?.wait) return; | ||
|
||
setIsFormDisabled(true); | ||
const timer = setTimeout(() => setIsFormDisabled(false), 1000 * 60); | ||
|
||
return () => clearTimeout(timer); | ||
}, [formState]); | ||
|
||
return ( | ||
<div className="flex max-w-xl flex-col gap-2"> | ||
<p> | ||
To delete your account, remove all the meet.hn informations from your HN | ||
description and click on the button below. | ||
</p> | ||
<form action={formAction} className="flex flex-col gap-2"> | ||
<Input | ||
name="username" | ||
type="text" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
placeholder="HN username" | ||
className="border-[#99999a]" | ||
/> | ||
<div className="flex items-center justify-between gap-3"> | ||
{formState && Object.keys(formState).length > 0 && ( | ||
<div | ||
className={cn( | ||
"text-sm", | ||
formState.success === true ? "text-green-800" : "text-red-800", | ||
)} | ||
> | ||
{formState.message} | ||
</div> | ||
)} | ||
<SubmitButton | ||
disabled={isFormDisabled || !username} | ||
className="ml-auto self-start bg-[#ff6602] hover:bg-[#e15b02]" | ||
> | ||
Remove me from the map | ||
</SubmitButton> | ||
</div> | ||
<p> | ||
Open your HN account here: | ||
<br /> | ||
<ExternalLink | ||
href={`https://news.ycombinator.com/user?id=${username.length === 0 ? "dang" : username}`} | ||
className="font-medium" | ||
> | ||
{username.length === 0 ? "dang" : username} | ||
</ExternalLink> | ||
{username.length === 0 ? ( | ||
<span className="inline italic"> | ||
{" "} | ||
⬅️ Placeholder username. Yours will be set here as soon as you | ||
fill it above. | ||
</span> | ||
) : null} | ||
</p> | ||
</form> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
|
@@ -46,15 +46,15 @@ export default async function Home({ | |
account and I'll retweet you. | ||
</p> | ||
<p> | ||
To give some feedback or remove your profile from meet.hn, drop me a DM | ||
on Twitter{" "} | ||
To give some feedback, drop me a DM on Twitter{" "} | ||
<ExternalLink | ||
href="https://x.com/borisfyi" | ||
target="_blank" | ||
className="font-medium" | ||
> | ||
@borisfyi | ||
</ExternalLink> | ||
</ExternalLink>{" "} | ||
or send a line to <b className="font-medium">[email protected]</b> | ||
</p> | ||
</> | ||
); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export async function getHnUserAboutSection(username: string) { | ||
const hnUser: null | { about: string } = await fetch( | ||
`https://hacker-news.firebaseio.com/v0/user/${username}.json`, | ||
).then((res) => res.json()); | ||
|
||
return hnUser?.about; | ||
} |
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,82 @@ | ||
"use server"; | ||
|
||
import { decode } from "he"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
import { getHnUserAboutSection } from "@/app/_actions/common/hn"; | ||
import { decrementCityHackerCount } from "@/app/_db/City"; | ||
import { deleteUser as deleteUserFromDb, getUser } from "@/app/_db/User"; | ||
|
||
export const deleteUser = async ( | ||
prevState: unknown, | ||
formData: FormData, | ||
): Promise<{ | ||
success: boolean; | ||
message: JSX.Element | string; | ||
wait?: boolean; | ||
}> => { | ||
const { username } = Object.fromEntries(formData); | ||
|
||
if (typeof username !== "string" || username === "") | ||
return { | ||
success: false, | ||
message: | ||
"Can't remove your account if you don't give me your username 🤷", | ||
}; | ||
|
||
const about = await getHnUserAboutSection(username); | ||
|
||
if (!about) return await deleteUserAndUpdateCity(username); | ||
|
||
const decodedAbout = decode(about); | ||
|
||
const fullMeetHnData = decodedAbout.match( | ||
/### meet\.hn\/\?city=(\S+)<p>([\s\S]*?)---/, | ||
); | ||
const cityOnlyMeetHnData = decodedAbout.match( | ||
/meet\.hn\/\?city=([^\n]+)\s*\n?/, | ||
); | ||
|
||
if (fullMeetHnData && cityOnlyMeetHnData) | ||
return { | ||
success: false, | ||
message: ( | ||
<p> | ||
Some meet.hn data still exists in the user HN description.{" "} | ||
<b>Waiting a minute to let HN API update.</b> | ||
</p> | ||
), | ||
wait: true, | ||
}; | ||
|
||
return await deleteUserAndUpdateCity(username); | ||
}; | ||
|
||
const deleteUserAndUpdateCity = async (username: string) => { | ||
const user = await getUser(username); | ||
if (!user) | ||
return { | ||
success: false, | ||
message: ( | ||
<p> | ||
<b>{username}</b> isn't registered on meet.hn | ||
</p> | ||
), | ||
}; | ||
|
||
// Delete user | ||
await deleteUserFromDb(username); | ||
|
||
// Update its city count | ||
decrementCityHackerCount(user.cityId); | ||
revalidatePath("/"); | ||
|
||
return { | ||
success: true, | ||
message: ( | ||
<p> | ||
<b>{username}</b> has been deleted successfully ✅ | ||
</p> | ||
), | ||
}; | ||
}; |
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.