Persist nick

This commit is contained in:
Franck Royer 2021-06-04 15:15:07 +10:00
parent b90b66c5f6
commit 6b48c55266
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 9 additions and 1 deletions

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Examples (web chat): Use `WakuMessage.timestamp` as unique key for list items. - Examples (web chat): Use `WakuMessage.timestamp` as unique key for list items.
- Doc: Link to new [topic guidelines](https://rfc.vac.dev/spec/23/) in README. - Doc: Link to new [topic guidelines](https://rfc.vac.dev/spec/23/) in README.
- Doc: Link to [Waku v2 Toy Chat specs](https://rfc.vac.dev/spec/22/) in README. - Doc: Link to [Waku v2 Toy Chat specs](https://rfc.vac.dev/spec/22/) in README.
- Examples (web chat): Persist nick.
## [0.5.0] - 2021-05-21 ## [0.5.0] - 2021-05-21

View File

@ -77,7 +77,14 @@ export default function App() {
let [newMessages, setNewMessages] = useState<Message[]>([]); let [newMessages, setNewMessages] = useState<Message[]>([]);
let [archivedMessages, setArchivedMessages] = useState<Message[]>([]); let [archivedMessages, setArchivedMessages] = useState<Message[]>([]);
let [stateWaku, setWaku] = useState<Waku | undefined>(undefined); let [stateWaku, setWaku] = useState<Waku | undefined>(undefined);
let [nick, setNick] = useState<string>(generate()); let [nick, setNick] = useState<string>(() => {
const persistedNick = window.localStorage.getItem('nick');
return persistedNick !== null ? persistedNick : generate();
});
useEffect(() => {
localStorage.setItem('nick', nick);
}, [nick]);
// Waku: Start, process messages, send messages // Waku: Start, process messages, send messages
useEffect(() => { useEffect(() => {