| import { atom } from 'nanostores'; |
|
|
| interface Profile { |
| username: string; |
| bio: string; |
| avatar: string; |
| } |
|
|
| |
| const storedProfile = typeof window !== 'undefined' ? localStorage.getItem('bolt_profile') : null; |
| const initialProfile: Profile = storedProfile |
| ? JSON.parse(storedProfile) |
| : { |
| username: '', |
| bio: '', |
| avatar: '', |
| }; |
|
|
| export const profileStore = atom<Profile>(initialProfile); |
|
|
| export const updateProfile = (updates: Partial<Profile>) => { |
| profileStore.set({ ...profileStore.get(), ...updates }); |
|
|
| |
| if (typeof window !== 'undefined') { |
| localStorage.setItem('bolt_profile', JSON.stringify(profileStore.get())); |
| } |
| }; |
|
|