Skip to content

Commit

Permalink
✨ persist user information when switching tabs (#251) (#253)
Browse files Browse the repository at this point in the history
* ✨ feat: persist user information when switching tabs (#251)
* ✨ feat: added nickname step information store
* 🎨 fix: use store alias
  • Loading branch information
rezk2ll authored Jun 10, 2024
1 parent 98acb6a commit e770b60
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import AvailableNicknames from '$components/user/AvailableNicknames.svelte';
import { env } from '$env/dynamic/public';
import { createUserFormSchema } from '$lib/schemas/zodSchema';
import { nickNameStepInfo } from '$store';
import { isNickNameTaken, suggestNickNames } from '$utils/api';
import { onDestroy, onMount } from 'svelte';
import { t } from 'svelte-i18n';
let firstName: string = '';
Expand Down Expand Up @@ -63,6 +65,28 @@
checkNicknameForm.requestSubmit();
};
onMount(() => {
const {
firstName: savedFirstName,
lastName: savedLastName,
nickName: savedNickname
} = $nickNameStepInfo;
firstName = savedFirstName;
lastName = savedLastName;
nickName = savedNickname;
checkNickName();
});
onDestroy(() => {
nickNameStepInfo.set({
firstName,
lastName,
nickName
});
});
</script>

<form
Expand Down
8 changes: 7 additions & 1 deletion registration/src/store/registration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RegistrationStepType } from '$types';
import type { UserInfo, RegistrationStepType } from '$types';
import { writable, get } from 'svelte/store';
import type { ActionData } from '../routes/$types';

Expand Down Expand Up @@ -34,3 +34,9 @@ export const nextRegistrationStep = () => {

if (currentStep === 'password') return registrationStep.set('success');
};

export const nickNameStepInfo = writable<UserInfo>({
firstName: '',
lastName: '',
nickName: ''
});
6 changes: 6 additions & 0 deletions registration/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ export interface lemonLDAPSessionInformation {
error?: number;
token?: string;
}

export interface UserInfo {
firstName: string;
lastName: string;
nickName: string;
}

0 comments on commit e770b60

Please sign in to comment.