2020-10-12 16:23:07 +02:00
|
|
|
import {LocalUser} from "./LocalUser";
|
|
|
|
|
2020-10-15 12:05:40 +02:00
|
|
|
//todo: add localstorage fallback
|
2020-10-12 16:23:07 +02:00
|
|
|
class LocalUserStore {
|
|
|
|
|
|
|
|
saveUser(localUser: LocalUser) {
|
|
|
|
localStorage.setItem('localUser', JSON.stringify(localUser));
|
|
|
|
}
|
|
|
|
|
|
|
|
getLocalUser(): LocalUser|null {
|
|
|
|
const data = localStorage.getItem('localUser');
|
|
|
|
return data ? JSON.parse(data) : null;
|
|
|
|
}
|
2020-10-15 12:05:40 +02:00
|
|
|
|
|
|
|
setName(name:string): void {
|
|
|
|
window.localStorage.setItem('playerName', name);
|
|
|
|
}
|
|
|
|
|
|
|
|
getName(): string {
|
|
|
|
return window.localStorage.getItem('playerName') ?? '';
|
|
|
|
}
|
2020-10-12 16:23:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export const localUserStore = new LocalUserStore();
|