bigbuffet-rw/app/soapbox/actions/onboarding.ts

41 lines
1 KiB
TypeScript
Raw Normal View History

2022-05-02 13:55:52 -07:00
const ONBOARDING_START = 'ONBOARDING_START';
const ONBOARDING_END = 'ONBOARDING_END';
2022-04-12 06:51:28 -07:00
2022-05-02 13:55:52 -07:00
const ONBOARDING_LOCAL_STORAGE_KEY = 'soapbox:onboarding';
2022-04-12 06:51:28 -07:00
2022-05-02 13:55:52 -07:00
type OnboardingStartAction = {
type: typeof ONBOARDING_START
}
type OnboardingEndAction = {
type: typeof ONBOARDING_END
}
export type OnboardingActions = OnboardingStartAction | OnboardingEndAction
const checkOnboardingStatus = () => (dispatch: React.Dispatch<OnboardingActions>) => {
const needsOnboarding = localStorage.getItem(ONBOARDING_LOCAL_STORAGE_KEY) === '1';
if (needsOnboarding) {
dispatch({ type: ONBOARDING_START });
}
};
const startOnboarding = () => (dispatch: React.Dispatch<OnboardingActions>) => {
localStorage.setItem(ONBOARDING_LOCAL_STORAGE_KEY, '1');
dispatch({ type: ONBOARDING_START });
};
const endOnboarding = () => (dispatch: React.Dispatch<OnboardingActions>) => {
localStorage.removeItem(ONBOARDING_LOCAL_STORAGE_KEY);
dispatch({ type: ONBOARDING_END });
2022-04-12 06:51:28 -07:00
};
export {
2022-05-02 13:55:52 -07:00
ONBOARDING_END,
ONBOARDING_START,
checkOnboardingStatus,
2022-04-12 06:51:28 -07:00
endOnboarding,
2022-05-02 13:55:52 -07:00
startOnboarding,
2022-04-12 06:51:28 -07:00
};