2025-12-08 16:31:30 +03:00

144 lines
5.1 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client'
import { useState, useEffect } from 'react'
import { useAccount } from 'wagmi'
import sdk from '@farcaster/frame-sdk'
interface Settings {
notifyOnVote: boolean
notifyOnComment: boolean
notifyOnFollow: boolean
notifyOnWin: boolean
displayName?: string
bio?: string
}
export default function SettingsPage() {
const { address } = useAccount()
const [settings, setSettings] = useState<Settings>({
notifyOnVote: true,
notifyOnComment: true,
notifyOnFollow: true,
notifyOnWin: true
})
const [saving, setSaving] = useState(false)
const [fid, setFid] = useState<string>('')
useEffect(() => {
sdk.context.then(ctx => {
if (ctx?.user?.fid) {
setFid(ctx.user.fid.toString())
fetch(`/api/user/settings?fid=${ctx.user.fid}`)
.then(r => r.json())
.then(data => setSettings(data))
}
})
}, [])
const handleSave = async () => {
setSaving(true)
await fetch('/api/user/settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ fid, ...settings })
})
setSaving(false)
}
return (
<div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4">
<div className="max-w-2xl mx-auto space-y-6">
<h1 className="text-3xl font-bold">⚙️ Settings</h1>
<div className="bg-white/10 rounded-xl p-6 space-y-6">
<div>
<h2 className="text-xl font-semibold mb-4">Profile</h2>
<div className="space-y-4">
<div>
<label className="block text-sm text-gray-400 mb-2">Display Name</label>
<input
type="text"
value={settings.displayName || ''}
onChange={(e) => setSettings({...settings, displayName: e.target.value})}
className="w-full px-4 py-2 bg-white/10 rounded-lg border border-white/20 focus:border-celo-green outline-none"
placeholder="Your display name"
/>
</div>
<div>
<label className="block text-sm text-gray-400 mb-2">Bio</label>
<textarea
value={settings.bio || ''}
onChange={(e) => setSettings({...settings, bio: e.target.value})}
className="w-full px-4 py-2 bg-white/10 rounded-lg border border-white/20 focus:border-celo-green outline-none"
placeholder="Tell us about yourself"
rows={3}
/>
</div>
</div>
</div>
<div>
<h2 className="text-xl font-semibold mb-4">Notifications</h2>
<div className="space-y-3">
<label className="flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={settings.notifyOnVote}
onChange={(e) => setSettings({...settings, notifyOnVote: e.target.checked})}
className="w-5 h-5"
/>
<span>Notify when someone votes on my polls</span>
</label>
<label className="flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={settings.notifyOnComment}
onChange={(e) => setSettings({...settings, notifyOnComment: e.target.checked})}
className="w-5 h-5"
/>
<span>Notify when someone comments</span>
</label>
<label className="flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={settings.notifyOnFollow}
onChange={(e) => setSettings({...settings, notifyOnFollow: e.target.checked})}
className="w-5 h-5"
/>
<span>Notify when someone follows me</span>
</label>
<label className="flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={settings.notifyOnWin}
onChange={(e) => setSettings({...settings, notifyOnWin: e.target.checked})}
className="w-5 h-5"
/>
<span>Notify when I win a poll</span>
</label>
</div>
</div>
{address && (
<div>
<h2 className="text-xl font-semibold mb-4">Connected Wallet</h2>
<div className="bg-white/5 rounded-lg p-4">
<p className="text-sm text-gray-400">Wallet Address</p>
<p className="font-mono text-sm mt-1">{address}</p>
</div>
</div>
)}
<button
onClick={handleSave}
disabled={saving}
className="w-full bg-celo-green text-black font-semibold py-3 rounded-xl hover:bg-celo-green/90 transition disabled:opacity-50"
>
{saving ? 'Saving...' : 'Save Settings'}
</button>
</div>
</div>
</div>
)
}