feat: simplify error handling in login and registration pages, add install prompt component, and update favicon and icons
@@ -42,7 +42,7 @@ export default function LoginPage() {
|
|||||||
const { token } = await loginUser(values);
|
const { token } = await loginUser(values);
|
||||||
setToken(token);
|
setToken(token);
|
||||||
router.push("/"); // Redirect to homepage on successful login
|
router.push("/"); // Redirect to homepage on successful login
|
||||||
} catch (err) {
|
} catch {
|
||||||
setError("Invalid username or password.");
|
setError("Invalid username or password.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ export default function RegisterPage() {
|
|||||||
await registerUser(values);
|
await registerUser(values);
|
||||||
// You can automatically log the user in here or just redirect them
|
// You can automatically log the user in here or just redirect them
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
} catch (err) {
|
} catch {
|
||||||
setError("Username or email may already be taken.");
|
setError("Username or email may already be taken.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 4.2 KiB |
@@ -4,6 +4,7 @@ import { AuthProvider } from "@/hooks/use-auth";
|
|||||||
import { Toaster } from "@/components/ui/sonner";
|
import { Toaster } from "@/components/ui/sonner";
|
||||||
import { Header } from "@/components/header";
|
import { Header } from "@/components/header";
|
||||||
import localFont from "next/font/local";
|
import localFont from "next/font/local";
|
||||||
|
import InstallPrompt from "@/components/install-prompt";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Thoughts",
|
title: "Thoughts",
|
||||||
@@ -37,6 +38,7 @@ export default function RootLayout({
|
|||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<Header />
|
<Header />
|
||||||
<main className="flex-1">{children}</main>
|
<main className="flex-1">{children}</main>
|
||||||
|
<InstallPrompt />
|
||||||
<Toaster />
|
<Toaster />
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</body>
|
</body>
|
||||||
|
25
thoughts-frontend/app/manifest.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import type { MetadataRoute } from 'next'
|
||||||
|
|
||||||
|
export default function manifest(): MetadataRoute.Manifest {
|
||||||
|
return {
|
||||||
|
name: 'Thoughts',
|
||||||
|
short_name: 'Thoughts',
|
||||||
|
description: 'A social network for sharing thoughts',
|
||||||
|
start_url: '/',
|
||||||
|
display: 'standalone',
|
||||||
|
background_color: '#ffffff',
|
||||||
|
theme_color: '#000000',
|
||||||
|
icons: [
|
||||||
|
{
|
||||||
|
src: '/icon-192x192.webp',
|
||||||
|
sizes: '192x192',
|
||||||
|
type: 'image/webp',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: '/icon.avif',
|
||||||
|
sizes: '512x512',
|
||||||
|
type: 'image/avif',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
@@ -14,6 +14,7 @@ import { PopularTags } from "@/components/popular-tags";
|
|||||||
import { ThoughtThread } from "@/components/thought-thread";
|
import { ThoughtThread } from "@/components/thought-thread";
|
||||||
import { buildThoughtThreads } from "@/lib/utils";
|
import { buildThoughtThreads } from "@/lib/utils";
|
||||||
import { TopFriends } from "@/components/top-friends";
|
import { TopFriends } from "@/components/top-friends";
|
||||||
|
import InstallPrompt from "@/components/install-prompt";
|
||||||
|
|
||||||
export default async function Home() {
|
export default async function Home() {
|
||||||
const token = (await cookies()).get("auth_token")?.value ?? null;
|
const token = (await cookies()).get("auth_token")?.value ?? null;
|
||||||
@@ -101,6 +102,7 @@ async function FeedPage({ token }: { token: string }) {
|
|||||||
|
|
||||||
function LandingPage() {
|
function LandingPage() {
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<div className="font-sans min-h-screen text-gray-800 flex items-center justify-center">
|
<div className="font-sans min-h-screen text-gray-800 flex items-center justify-center">
|
||||||
<div className="container mx-auto max-w-2xl p-4 sm:p-6 text-center glass-effect glossy-effect bottom rounded-md shadow-fa-lg">
|
<div className="container mx-auto max-w-2xl p-4 sm:p-6 text-center glass-effect glossy-effect bottom rounded-md shadow-fa-lg">
|
||||||
<h1
|
<h1
|
||||||
@@ -122,5 +124,6 @@ function LandingPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ export function FollowButton({
|
|||||||
setIsFollowing(!isFollowing);
|
setIsFollowing(!isFollowing);
|
||||||
await action(username, token);
|
await action(username, token);
|
||||||
router.refresh(); // Re-fetch server component data to get the latest follower count etc.
|
router.refresh(); // Re-fetch server component data to get the latest follower count etc.
|
||||||
} catch (err) {
|
} catch {
|
||||||
// Revert on error
|
// Revert on error
|
||||||
setIsFollowing(isFollowing);
|
setIsFollowing(isFollowing);
|
||||||
toast.error(`Failed to ${isFollowing ? "unfollow" : "follow"} user.`);
|
toast.error(`Failed to ${isFollowing ? "unfollow" : "follow"} user.`);
|
||||||
|
107
thoughts-frontend/components/install-prompt.tsx
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Download } from "lucide-react";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
CardDescription,
|
||||||
|
CardContent,
|
||||||
|
CardAction,
|
||||||
|
} from "@/components/ui/card";
|
||||||
|
|
||||||
|
interface CustomWindow extends Window {
|
||||||
|
MSStream?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BeforeInstallPromptEvent extends Event {
|
||||||
|
prompt: () => void;
|
||||||
|
userChoice: Promise<{ outcome: "accepted" | "dismissed"; platform: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function InstallPrompt() {
|
||||||
|
const [isIOS, setIsIOS] = useState(false);
|
||||||
|
const [isStandalone, setIsStandalone] = useState(false);
|
||||||
|
const [deferredPrompt, setDeferredPrompt] =
|
||||||
|
useState<BeforeInstallPromptEvent | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Cast window to our custom type instead of 'any'
|
||||||
|
const customWindow = window as CustomWindow;
|
||||||
|
setIsIOS(
|
||||||
|
/iPad|iPhone|iPod/.test(navigator.userAgent) && !customWindow.MSStream
|
||||||
|
);
|
||||||
|
setIsStandalone(window.matchMedia("(display-mode: standalone)").matches);
|
||||||
|
|
||||||
|
const handleBeforeInstallPrompt = (e: Event) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setDeferredPrompt(e as BeforeInstallPromptEvent);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("beforeinstallprompt", handleBeforeInstallPrompt);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener(
|
||||||
|
"beforeinstallprompt",
|
||||||
|
handleBeforeInstallPrompt
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleInstallClick = async () => {
|
||||||
|
if (!deferredPrompt) return;
|
||||||
|
deferredPrompt.prompt();
|
||||||
|
const { outcome } = await deferredPrompt.userChoice;
|
||||||
|
if (outcome === "accepted") {
|
||||||
|
console.log("User accepted the install prompt");
|
||||||
|
} else {
|
||||||
|
console.log("User dismissed the install prompt");
|
||||||
|
}
|
||||||
|
setDeferredPrompt(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isStandalone || (!isIOS && !deferredPrompt)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed bottom-0 z-50">
|
||||||
|
<Card className="w-full max-w-sm glass-effect glossy-effect bottom shadow-fa-lg">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Install Thoughts</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Get the full app experience on your device.
|
||||||
|
</CardDescription>
|
||||||
|
<CardAction>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
className="absolute top-2 right-2"
|
||||||
|
onClick={() => setIsStandalone(true)}
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</Button>
|
||||||
|
</CardAction>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{!isIOS && deferredPrompt && (
|
||||||
|
<Button className="w-full" onClick={handleInstallClick}>
|
||||||
|
<Download className="mr-2 h-4 w-4" />
|
||||||
|
Add to Home Screen
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{isIOS && (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
To install, tap the Share icon
|
||||||
|
<span className="mx-1 text-lg">⎋</span>
|
||||||
|
and then "Add to Home Screen"
|
||||||
|
<span className="mx-1 text-lg">➕</span>.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@@ -17,7 +17,7 @@ const buttonVariants = cva(
|
|||||||
"glass-effect fa-gradient-green text-secondary-foreground shadow-fa-md hover:bg-secondary/90 active:shadow-fa-inner transition-transform active:scale-[0.98] glossy-effect",
|
"glass-effect fa-gradient-green text-secondary-foreground shadow-fa-md hover:bg-secondary/90 active:shadow-fa-inner transition-transform active:scale-[0.98] glossy-effect",
|
||||||
// Ghost and Link should be more subtle
|
// Ghost and Link should be more subtle
|
||||||
ghost:
|
ghost:
|
||||||
"glass-effect hover:bg-accent hover:text-accent-foreground rounded-lg", // Keep them simple, maybe a slight blur/gloss on hover
|
"glass-effect hover:bg-accent hover:text-accent-foreground rounded-lg",
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
// Outline button for a transparent-ish, glassy feel
|
// Outline button for a transparent-ish, glassy feel
|
||||||
outline:
|
outline:
|
||||||
|
BIN
thoughts-frontend/public/icon-128x128.webp
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
thoughts-frontend/public/icon-144x144.webp
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
thoughts-frontend/public/icon-152x152.webp
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
thoughts-frontend/public/icon-192x192.webp
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
thoughts-frontend/public/icon-256x256.webp
Normal file
After Width: | Height: | Size: 9.7 KiB |
BIN
thoughts-frontend/public/icon-384x384.webp
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
thoughts-frontend/public/icon-48x48.webp
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
thoughts-frontend/public/icon-512x512.webp
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
thoughts-frontend/public/icon-72x72.webp
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
thoughts-frontend/public/icon-96x96.webp
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
thoughts-frontend/public/icon.avif
Normal file
After Width: | Height: | Size: 9.2 KiB |