Onboarding
This commit is contained in:
@@ -1,21 +1,31 @@
|
||||
import { OnboardingProfileDb } from './database';
|
||||
|
||||
export type PersistentOnboardingStep = 'lexicon' | 'customize';
|
||||
export type PersistentOnboardingStep = 'lexicon' | 'customize' | 'scan' | 'reminder' | 'collection';
|
||||
|
||||
const STEP_COLUMN: Record<PersistentOnboardingStep, 'lexicon_explored' | 'customization_done' | 'scan_done' | 'reminder_done' | 'collection_done'> = {
|
||||
lexicon: 'lexicon_explored',
|
||||
customize: 'customization_done',
|
||||
scan: 'scan_done',
|
||||
reminder: 'reminder_done',
|
||||
collection: 'collection_done',
|
||||
};
|
||||
|
||||
const STEP_SETTER: Record<PersistentOnboardingStep, (userId: number, done: boolean) => void> = {
|
||||
lexicon: OnboardingProfileDb.setLexiconExplored,
|
||||
customize: OnboardingProfileDb.setCustomizationDone,
|
||||
scan: OnboardingProfileDb.setScanDone,
|
||||
reminder: OnboardingProfileDb.setReminderDone,
|
||||
collection: OnboardingProfileDb.setCollectionDone,
|
||||
};
|
||||
|
||||
export const OnboardingProgressService = {
|
||||
isStepCompleted(userId: number, step: PersistentOnboardingStep): boolean {
|
||||
const profile = OnboardingProfileDb.get(userId);
|
||||
return step === 'lexicon'
|
||||
? profile.lexicon_explored === 1
|
||||
: profile.customization_done === 1;
|
||||
return profile[STEP_COLUMN[step]] === 1;
|
||||
},
|
||||
|
||||
completeStep(userId: number, step: PersistentOnboardingStep): void {
|
||||
if (step === 'lexicon') {
|
||||
OnboardingProfileDb.setLexiconExplored(userId, true);
|
||||
return;
|
||||
}
|
||||
OnboardingProfileDb.setCustomizationDone(userId, true);
|
||||
STEP_SETTER[step](userId, true);
|
||||
},
|
||||
|
||||
getSignals(userId: number) {
|
||||
@@ -23,6 +33,9 @@ export const OnboardingProgressService = {
|
||||
return {
|
||||
lexiconExplored: profile.lexicon_explored === 1,
|
||||
customizationDone: profile.customization_done === 1,
|
||||
scanDone: profile.scan_done === 1,
|
||||
reminderDone: profile.reminder_done === 1,
|
||||
collectionDone: profile.collection_done === 1,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user