feat: update dashboard to use NextAuth session, show user name, fix avatar component usage
This commit is contained in:
+119
-84
@@ -1,74 +1,81 @@
|
|||||||
import { useSession, signOut } from "next-auth/react"
|
import { useState } from "react"
|
||||||
import { useRouter } from "next/router"
|
import { useRouter } from "next/router"
|
||||||
import { useState, useEffect } from "react"
|
import { useSession, signOut } from "next-auth/react"
|
||||||
import AvatarSelector from "../components/AvatarSelector"
|
import AvatarSelector from "../components/AvatarSelector"
|
||||||
import CategoryMenu from "../components/CategoryMenu"
|
import CategoryMenu from "../components/CategoryMenu"
|
||||||
|
|
||||||
// Apps organizados por categoria
|
|
||||||
const ALL_APPS = [
|
|
||||||
// Produtividade
|
|
||||||
{ id: 1, name: "Tendências Semanais", desc: "Notícias em alta • Top 100", path: "/apps/trendsnews", icon: "📈", category: "produtividade", favorite: false },
|
|
||||||
{ id: 2, name: "Conversor", desc: "Conversão de unidades", path: "/apps/converter", icon: "🔄", category: "produtividade", favorite: false },
|
|
||||||
{ id: 3, name: "Calculadora", desc: "Calculos rápidos", path: "/apps/calculator", icon: "🧮", category: "produtividade", favorite: false },
|
|
||||||
|
|
||||||
// Utilidades
|
|
||||||
{ id: 4, name: "Relógio", desc: "Relógio mundial", path: "/apps/clock", icon: "⏰", category: "utilidades", favorite: false },
|
|
||||||
{ id: 5, name: "Gerador Senhas", desc: "Senhas seguras", path: "/apps/password-generator", icon: "🔐", category: "utilidades", favorite: false },
|
|
||||||
{ id: 6, name: "QR Code", desc: "Gerador QR", path: "/apps/qrcode", icon: "📱", category: "utilidades", favorite: false },
|
|
||||||
{ id: 7, name: "Cronômetro", desc: "Tempo e alarmes", path: "/apps/timer", icon: "⏱️", category: "utilidades", favorite: false },
|
|
||||||
|
|
||||||
// Games
|
|
||||||
{ id: 8, name: "Jogo da Velha", desc: "Jogo da velha clássico 2 jogadores", path: "/apps/tictactoe", icon: "⭕", category: "games", favorite: false },
|
|
||||||
{ id: 14, name: "Expedição Gold", path: "/apps/expedicao", icon: "🗺️", category: "games", desc: "Expedições para conquistar ouro" },
|
|
||||||
{ id: 15, name: "Human City", path: "/apps/humancity", icon: "🏙️", category: "games", desc: "Simulação de cidade estilo Sims" },
|
|
||||||
{ id: 16, name: "Aurea", path: "/apps/aurea", icon: "👑", category: "games", desc: "Simulador de vida e riqueza" },
|
|
||||||
{ id: 17, name: "TerraVerse", path: "/apps/terraverse", icon: "🌍", category: "games", desc: "Game de realidade aumentada" },
|
|
||||||
|
|
||||||
// Ferramentas
|
|
||||||
{ id: 9, name: "Editor Texto", desc: "Texto simples", path: "/apps/text-editor", icon: "📝", category: "ferramentas", favorite: false },
|
|
||||||
{ id: 10, name: "Conversor Moedas", desc: "Câmbio em tempo real", path: "/apps/currency", icon: "💱", category: "ferramentas", favorite: false },
|
|
||||||
|
|
||||||
// Educação
|
|
||||||
{ id: 11, name: "Dicionário", desc: "Significados", path: "/apps/dictionary", icon: "📖", category: "educacao", favorite: false },
|
|
||||||
{ id: 12, name: "Tradutor", desc: "Multi-idiomas", path: "/apps/translator", icon: "🌐", category: "educacao", favorite: false },
|
|
||||||
|
|
||||||
// Esportes
|
|
||||||
{ id: 13, name: "Copa do Mundo 2026", desc: "Tabela, grupos, notícias", path: "/apps/worldcup2026", icon: "⚽", category: "esportes", favorite: false }
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
const { data: session } = useSession()
|
const { data: session } = useSession()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [selectedAvatar, setSelectedAvatar] = useState("😀")
|
const [selectedAvatar, setSelectedAvatar] = useState("😀")
|
||||||
const [selectedCategory, setSelectedCategory] = useState("all")
|
const [selectedCategory, setSelectedCategory] = useState("all")
|
||||||
const [favorites, setFavorites] = useState([])
|
const [favorites, setFavorites] = useState([])
|
||||||
const [apps, setApps] = useState(ALL_APPS)
|
const [confirmPassword, setConfirmPassword] = useState("")
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
// Apps organized by category
|
||||||
|
const ALL_APPS = [
|
||||||
|
// Produtividade
|
||||||
|
{ id: 1, name: "Tendências Semanais", desc: "Notícias em alta • Top 100", path: "/apps/trendsnews", icon: "📈", category: "produtividade", favorite: false },
|
||||||
|
{ id: 2, name: "Conversor", desc: "Conversão de unidades", path: "/apps/converter", icon: "🔄", category: "produtividade", favorite: false },
|
||||||
|
{ id: 3, name: "Calculadora", desc: "Cálculos rápidos", path: "/apps/calculator", icon: "🧮", category: "produtividade", favorite: false },
|
||||||
|
|
||||||
|
// Utilidades
|
||||||
|
{ id: 4, name: "Relógio", desc: "Relógio mundial", path: "/apps/clock", icon: "⏰", category: "utilidades", favorite: false },
|
||||||
|
{ id: 5, name: "Gerador Senhas", desc: "Senhas seguras", path: "/apps/password-generator", icon: "🔐", category: "utilidades", favorite: false },
|
||||||
|
{ id: 6, name: "QR Code", desc: "Gerador QR", path: "/apps/qrcode", icon: "📱", category: "utilidades", favorite: false },
|
||||||
|
{ id: 7, name: "Cronômetro", desc: "Tempo e alarmes", path: "/apps/timer", icon: "⏱️", category: "utilidades", favorite: false },
|
||||||
|
|
||||||
|
// Games
|
||||||
|
{ id: 8, name: "Jogo da Velha", desc: "Jogo da velha clássico 2 jogadores", path: "/apps/tictactoe", icon: "⭕", category: "games", favorite: false },
|
||||||
|
{ id: 14, name: "Expedição Gold", desc: "Expedições para conquistar ouro", path: "/apps/expedicao", icon: "🗺️", category: "games", favorite: false },
|
||||||
|
{ id: 15, name: "Human City", desc: "Simulação de cidade estilo Sims", path: "/apps/humancity", icon: "🏙️", category: "games", favorite: false },
|
||||||
|
{ id: 16, name: "Aurea", desc: "Simulador de vida e riqueza", path: "/apps/aurea", icon: "👑", category: "games", favorite: false },
|
||||||
|
{ id: 17, name: "TerraVerse", desc: "Game de realidade aumentada", path: "/apps/terraverse", icon: "🌍", category: "games", favorite: false },
|
||||||
|
|
||||||
|
// Ferramentas
|
||||||
|
{ id: 9, name: "Editor Texto", desc: "Texto simples", path: "/apps/text-editor", icon: "📝", category: "ferramentas", favorite: false },
|
||||||
|
{ id: 10, name: "Conversor Moedas", desc: "Câmbio em tempo real", path: "/apps/currency", icon: "💱", category: "ferramentas", favorite: false },
|
||||||
|
|
||||||
|
// Educação
|
||||||
|
{ id: 11, name: "Dicionário", desc: "Significados", path: "/apps/dictionary", icon: "📖", category: "educacao", favorite: false },
|
||||||
|
{ id: 12, name: "Tradutor", desc: "Multi-idiomas", path: "/apps/translator", icon: "🌐", category: "educacao", favorite: false },
|
||||||
|
|
||||||
|
// Esportes
|
||||||
|
{ id: 13, name: "Copa do Mundo 2026", desc: "Tabela, grupos, notícias", path: "/apps/worldcup2026", icon: "⚽", category: "esportes", favorite: false }
|
||||||
|
]
|
||||||
|
|
||||||
// Carregar favoritos do localStorage
|
// Carregar favoritos do localStorage
|
||||||
useEffect(() => {
|
React.useEffect(() => {
|
||||||
const savedFavorites = localStorage.getItem("favorites")
|
const saved = localStorage.getItem("favorites")
|
||||||
const savedAvatar = localStorage.getItem("selectedAvatar")
|
if (saved) {
|
||||||
if (savedFavorites) {
|
try {
|
||||||
setFavorites(JSON.parse(savedFavorites))
|
setFavorites(JSON.parse(saved))
|
||||||
}
|
} catch (e) {
|
||||||
if (savedAvatar) {
|
console.warn("Failed to parse favorites from localStorage", e)
|
||||||
setSelectedAvatar(savedAvatar)
|
}
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Salvar favoritos no localStorage
|
// Salvar favoritos no localStorage
|
||||||
useEffect(() => {
|
React.useEffect(() => {
|
||||||
localStorage.setItem("favorites", JSON.stringify(favorites))
|
localStorage.setItem("favorites", JSON.stringify(favorites))
|
||||||
}, [favorites])
|
}, [favorites])
|
||||||
|
|
||||||
// Salvar avatar no localStorage
|
// Salvar avatar no localStorage
|
||||||
useEffect(() => {
|
React.useEffect(() => {
|
||||||
localStorage.setItem("selectedAvatar", selectedAvatar)
|
localStorage.setItem("selectedAvatar", selectedAvatar)
|
||||||
}, [selectedAvatar])
|
}, [selectedAvatar])
|
||||||
|
|
||||||
|
// Carregar avatar do localStorage
|
||||||
|
React.useEffect(() => {
|
||||||
|
const saved = localStorage.getItem("selectedAvatar")
|
||||||
|
if (saved) setSelectedAvatar(saved)
|
||||||
|
}, [])
|
||||||
|
|
||||||
const toggleFavorite = (appId) => {
|
const toggleFavorite = (appId) => {
|
||||||
setFavorites(prev =>
|
setFavorites(prev =>
|
||||||
prev.includes(appId)
|
prev.includes(appId)
|
||||||
? prev.filter(id => id !== appId)
|
? prev.filter(id => id !== appId)
|
||||||
: [...prev, appId]
|
: [...prev, appId]
|
||||||
)
|
)
|
||||||
@@ -76,11 +83,11 @@ export default function Dashboard() {
|
|||||||
|
|
||||||
// Filtrar apps
|
// Filtrar apps
|
||||||
const filteredApps = selectedCategory === "all"
|
const filteredApps = selectedCategory === "all"
|
||||||
? apps
|
? ALL_APPS
|
||||||
: apps.filter(app => app.category === selectedCategory)
|
: ALL_APPS.filter(app => app.category === selectedCategory)
|
||||||
|
|
||||||
// Apps favoritos
|
// Apps favoritos
|
||||||
const favoriteApps = apps.filter(app => favorites.includes(app.id))
|
const favoriteApps = ALL_APPS.filter(app => favorites.includes(app.id))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50">
|
<div className="min-h-screen bg-gray-50">
|
||||||
@@ -88,15 +95,27 @@ export default function Dashboard() {
|
|||||||
<nav className="bg-white shadow-lg p-4 flex justify-between items-center">
|
<nav className="bg-white shadow-lg p-4 flex justify-between items-center">
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<h1 className="text-2xl font-bold">1000Apps</h1>
|
<h1 className="text-2xl font-bold">1000Apps</h1>
|
||||||
<span className="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full font-semibold">FREE</span>
|
<span className="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full font-semibold">
|
||||||
|
FREE
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<AvatarSelector selectedAvatar={selectedAvatar} onSelect={setSelectedAvatar} />
|
<AvatarSelector
|
||||||
<span className="text-gray-600">Olá, {session?.user?.name || session?.user?.username || "usuário"}!</span>
|
selectedAvatar={selectedAvatar}
|
||||||
<button onClick={() => signOut()} className="text-red-600 hover:underline font-medium">Sair</button>
|
onSelect={setSelectedAvatar}
|
||||||
|
/>
|
||||||
|
<span className="text-gray-600">
|
||||||
|
Olá, {session?.user?.name || session?.user?.username || "usuário"}!
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => signOut({ callbackUrl: "/" })}
|
||||||
|
className="text-red-600 hover:underline font-medium"
|
||||||
|
>
|
||||||
|
Sair
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<main className="max-w-6xl mx-auto p-6">
|
<main className="max-w-6xl mx-auto p-6">
|
||||||
{/* Favoritos Section */}
|
{/* Favoritos Section */}
|
||||||
{favorites.length > 0 && (
|
{favorites.length > 0 && (
|
||||||
@@ -105,45 +124,67 @@ export default function Dashboard() {
|
|||||||
<span>⭐</span> Favoritos
|
<span>⭐</span> Favoritos
|
||||||
</h2>
|
</h2>
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||||
{favoriteApps.map(app => (
|
{favorites.map((favId) => {
|
||||||
<button
|
const app = ALL_APPS.find((a) => a.id === favId)
|
||||||
key={app.id}
|
if (!app) return null
|
||||||
onClick={() => router.push(app.path)}
|
return (
|
||||||
className="bg-white rounded-xl p-6 shadow-md hover:shadow-lg transition-all text-left hover:scale-105 cursor-pointer border-2 border-yellow-200"
|
<div key={app.id} className="relative">
|
||||||
>
|
<button
|
||||||
<div className="text-3xl mb-2">{app.icon}</div>
|
onClick={() => router.push(app.path)}
|
||||||
<h3 className="font-semibold text-gray-800 text-sm">{app.name}</h3>
|
className="bg-white rounded-xl p-6 shadow-md hover:shadow-lg transition-all text-left hover:scale-105 cursor-pointer w-full"
|
||||||
<p className="text-xs text-gray-500 mt-1">{app.desc}</p>
|
>
|
||||||
</button>
|
<div className="text-3xl mb-2">{app.icon}</div>
|
||||||
))}
|
<h3 className="font-semibold text-gray-800 text-sm">{app.name}</h3>
|
||||||
|
<p className="text-xs text-gray-500 mt-1">{app.desc}</p>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => toggleFavorite(app.id)}
|
||||||
|
className="absolute top-2 right-2 text-lg"
|
||||||
|
title={favorites.includes(favId) ? "Remover dos favoritos" : "Adicionar aos favoritos"}
|
||||||
|
>
|
||||||
|
{favorites.includes(favId) ? "⭐" : "☆"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Category Filter */}
|
{/* Category Filter */}
|
||||||
<CategoryMenu selectedCategory={selectedCategory} onSelect={setSelectedCategory} />
|
<CategoryMenu
|
||||||
|
selectedCategory={selectedCategory}
|
||||||
|
onSelect={setSelectedCategory}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Apps Grid */}
|
{/* Apps Grid */}
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<h2 className="text-3xl font-bold text-gray-800 mb-2">
|
<h2 className="text-3xl font-bold text-gray-800 mb-2">
|
||||||
{selectedCategory === "all" ? "Todos os Apps" :
|
{selectedCategory === "all"
|
||||||
selectedCategory === "produtividade" ? "Produtividade" :
|
? "Todos os Apps"
|
||||||
selectedCategory === "utilidades" ? "Utilidades" :
|
: selectedCategory === "produtividade"
|
||||||
selectedCategory === "games" ? "Games" :
|
? "Produtividade"
|
||||||
selectedCategory === "ferramentas" ? "Ferramentas" :
|
: selectedCategory === "utilidades"
|
||||||
selectedCategory === "educacao" ? "Educação" :
|
? "Utilidades"
|
||||||
selectedCategory === "entretenimento" ? "Entretenimento" :
|
: selectedCategory === "games"
|
||||||
selectedCategory === "esportes" ? "Esportes" : "Apps"}
|
? "Games"
|
||||||
|
: selectedCategory === "ferramentas"
|
||||||
|
? "Ferramentas"
|
||||||
|
: selectedCategory === "educacao"
|
||||||
|
? "Educação"
|
||||||
|
: selectedCategory === "esportes"
|
||||||
|
? "Esportes"
|
||||||
|
: "Apps"}
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-gray-500">
|
<p className="text-gray-500">
|
||||||
{selectedCategory === "all"
|
{selectedCategory === "all"
|
||||||
? `${apps.length} apps disponíveis`
|
? `${ALL_APPS.length} apps disponíveis`
|
||||||
: `${filteredApps.length} apps nesta categoria`}
|
: `${filteredApps.length} apps nesta categoria`}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||||
{filteredApps.map(app => (
|
{filteredApps.map((app) => (
|
||||||
<div key={app.id} className="relative">
|
<div key={app.id} className="relative">
|
||||||
<button
|
<button
|
||||||
onClick={() => router.push(app.path)}
|
onClick={() => router.push(app.path)}
|
||||||
@@ -166,10 +207,4 @@ export default function Dashboard() {
|
|||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
export async function getServerSideProps() {
|
|
||||||
return {
|
|
||||||
props: {},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user