logout from identity component

This commit is contained in:
balzack 2024-09-04 17:53:06 -07:00
parent daeefa75af
commit c2bf0e129e
5 changed files with 9 additions and 12 deletions

View File

@ -9,19 +9,15 @@ import {
} from '@tabler/icons-react' } from '@tabler/icons-react'
import { modals } from '@mantine/modals'; import { modals } from '@mantine/modals';
export function Identity({ settings, contacts }) { export function Identity({ settings, contacts }: { settings: () => void, contacts: () => void }) {
const { state, actions } = useIdentity(); const { state, actions } = useIdentity();
const [all, setAll] = useState(false); const [all, setAll] = useState(false);
const click = (ev) => {
console.log("CLICK", ev.currentTarget.checked);
}
const logout = () => modals.openConfirmModal({ const logout = () => modals.openConfirmModal({
title: state.strings.confirmLogout, title: state.strings.confirmLogout,
withCloseButton: false, withCloseButton: false,
children: ( children: (
<Switch label={state.strings.allDevices} value={all} size="md" onChange={(ev) => actions.setAll(ev.currentTarget.checked)} /> <Switch label={state.strings.allDevices} size="md" onChange={(ev) => actions.setAll(ev.currentTarget.checked)} />
), ),
labels: { confirm: state.strings.logout, cancel: state.strings.cancel }, labels: { confirm: state.strings.logout, cancel: state.strings.cancel },
onConfirm: actions.logout, onConfirm: actions.logout,

View File

@ -17,7 +17,7 @@ export function useIdentity() {
} }
const actions = { const actions = {
setAll: (all) => { setAll: (all: boolean) => {
updateState({ all }); updateState({ all });
}, },
logout: async () => { logout: async () => {

View File

@ -34,6 +34,7 @@ export function useSettings() {
} }
settings.addConfigListener(setConfig); settings.addConfigListener(setConfig);
const setProfile = (profile: Profile) => { const setProfile = (profile: Profile) => {
console.log("URL: ", identity.getProfileImageUrl());
updateState({ profile }) updateState({ profile })
} }
identity.addProfileListener(setProfile) identity.addProfileListener(setProfile)

View File

@ -65,7 +65,7 @@ export class IdentityModule implements Identity {
await this.store.setProfileData(guid, profile); await this.store.setProfileData(guid, profile);
await this.store.setProfileRevision(guid, nextRev); await this.store.setProfileRevision(guid, nextRev);
this.profile = profile; this.profile = profile;
this.emitter.emit('profile', this.getProfile()); this.emitter.emit('profile', this.setProfile());
this.revision = nextRev; this.revision = nextRev;
if (this.nextRevision === nextRev) { if (this.nextRevision === nextRev) {
this.nextRevision = null; this.nextRevision = null;
@ -82,14 +82,14 @@ export class IdentityModule implements Identity {
} }
} }
public getProfile() { public setProfile() {
const { guid, handle, name, description, location, image, revision, seal, version, node } = this.profile; const { guid, handle, name, description, location, image, revision, seal, version, node } = this.profile;
return { guid, handle, name, description, location, image, version, node, sealSet: Boolean(seal) }; return { guid, handle, name, description, location, imageSet: Boolean(image), version, node, sealSet: Boolean(seal) };
} }
public addProfileListener(ev: (profile: Profile) => void): void { public addProfileListener(ev: (profile: Profile) => void): void {
this.emitter.on('profile', ev); this.emitter.on('profile', ev);
this.emitter.emit('profile', this.getProfile()); this.emitter.emit('profile', this.setProfile());
} }
public removeProfileListener(ev: (profile: Profile) => void): void { public removeProfileListener(ev: (profile: Profile) => void): void {

View File

@ -157,7 +157,7 @@ export type Profile = {
name: string, name: string,
description: string, description: string,
location: string, location: string,
image: string, imageSet: boolean,
sealSet: boolean, sealSet: boolean,
version: string, version: string,
node: string, node: string,