Skip to content

Commit

Permalink
Merge pull request #4255 from tloncorp/lb/fix-onboarding-nickname
Browse files Browse the repository at this point in the history
native: fix onboarding nickname
  • Loading branch information
latter-bolden authored Dec 5, 2024
2 parents 9ceb955 + 79b1da8 commit 1e06b15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions apps/tlon-mobile/src/screens/Onboarding/ReserveShipScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import { useLureMetadata } from '@tloncorp/app/contexts/branch';
import { useSignupContext } from '.././../lib/signupContext';
import { NodeBootPhase } from '@tloncorp/app/lib/bootHelpers';
import {
ArvosDiscussing,
Expand All @@ -14,6 +13,7 @@ import {
} from '@tloncorp/ui';
import { useEffect, useMemo } from 'react';

import { useSignupContext } from '../../lib/signupContext';
import type { OnboardingStackParamList } from '../../types';

type Props = NativeStackScreenProps<OnboardingStackParamList, 'ReserveShip'>;
Expand All @@ -36,7 +36,7 @@ export const ReserveShipScreen = ({ navigation }: Props) => {
signupContext.setOnboardingValues({ didCompleteOnboarding: true });
}
signupContext.kickOffBootSequence();
}, []);
}, [signupContext]);

return (
<View flex={1} backgroundColor="$secondaryBackground">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
import { useEffect } from 'react';
import { Controller, useForm } from 'react-hook-form';

import { useSignupContext } from '../../lib/signupContext';
import type { OnboardingStackParamList } from '../../types';
import { useSignupContext } from '.././../lib/signupContext';

type Props = NativeStackScreenProps<OnboardingStackParamList, 'SetNickname'>;

Expand Down
35 changes: 21 additions & 14 deletions packages/shared/src/db/keyValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,31 +200,38 @@ const createStorageItem = <T>(config: StorageItem<T>) => {
deserialize = JSON.parse,
} = config;
const storage = getStorageMethods(config.isSecure ?? false);
let updateLock = Promise.resolve();

const getValue = async (): Promise<T> => {
const value = await storage.getItem(key);
return value ? deserialize(value) : defaultValue;
};

const resetValue = async (): Promise<T> => {
await storage.setItem(key, serialize(defaultValue));
queryClient.invalidateQueries({ queryKey: [key] });
logger.log(`reset value ${key}`);
updateLock = updateLock.then(async () => {
await storage.setItem(key, serialize(defaultValue));
queryClient.invalidateQueries({ queryKey: [key] });
logger.log(`reset value ${key}`);
});
await updateLock;
return defaultValue;
};

const setValue = async (valueInput: T | ((curr: T) => T)): Promise<void> => {
let newValue: T;
if (valueInput instanceof Function) {
const currValue = await getValue();
newValue = valueInput(currValue);
} else {
newValue = valueInput;
}

await storage.setItem(key, serialize(newValue));
queryClient.invalidateQueries({ queryKey: [key] });
logger.log(`set value ${key}`, newValue);
updateLock = updateLock.then(async () => {
let newValue: T;
if (valueInput instanceof Function) {
const currValue = await getValue();
newValue = valueInput(currValue);
} else {
newValue = valueInput;
}

await storage.setItem(key, serialize(newValue));
queryClient.invalidateQueries({ queryKey: [key] });
logger.log(`set value ${key}`, newValue);
});
await updateLock;
};

function useValue() {
Expand Down

0 comments on commit 1e06b15

Please sign in to comment.