Skip to content

Commit

Permalink
chore: bookingStore에 onboardingHasShown 플래그 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
potados99 committed Sep 28, 2021
1 parent f19cf29 commit 1a19d25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/presentation/features/booking/BookingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ import CafeteriaStore from '../cafeteria/CafeteriaStore';
import GetBookingOptions from '../../../domain/usecases/GetBookingOptions';
import BookingOptionView from './BookingOptionView';
import {makeAutoObservable} from 'mobx';
import AsyncStorage from '@react-native-async-storage/async-storage';

export default class BookingStore {
private _onboardingHasShown = false;
get onboardingHasShown() {
return this._onboardingHasShown;
}
set onboardingHasShown(value) {
this._onboardingHasShown = value;
}

private _bookingOptions: Map<number, BookingOptionView[]> = new Map();
getBookingOptions(cafeteriaId: number) {
return this._bookingOptions.get(cafeteriaId) ?? [];
Expand Down Expand Up @@ -68,6 +77,14 @@ export default class BookingStore {
makeAutoObservable(this);
}

async fetchOnboardingShownStatus() {
this.onboardingHasShown = (await AsyncStorage.getItem('booking_onboarding_has_shown')) === 'true';
}

async persistOnboardingShownStatus() {
await AsyncStorage.setItem('booking_onboarding_has_shown', String(this.onboardingHasShown));
}

async fetchBookingOptions(cafeteria: CafeteriaView) {
const bookingOptions = await GetBookingOptions.run({cafeteriaId: cafeteria.id});

Expand Down
15 changes: 12 additions & 3 deletions src/store/RootStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,27 @@ export default class RootStore {
}

private async initialize() {
// 로그인이 필요한 flow
const loggingIn = () => this.userStore.rememberedLogin();
const fetchingMyBookings = () => this.bookingStore.fetchMyBookings();

// 로그인이 필요없는 flow
const gettingCafeteria = () => this.cafeteriaStore.fetchCafeteria();
const fetchingNewNotice = () => this.noticeStore.fetchNewNotice();
const fetchOnboardingShownStatus = () => this.bookingStore.fetchOnboardingShownStatus();

const thoseNeedLogin = loggingIn()
.then(fetchingMyBookings)
.catch(e => console.log(`로그인하고 예약 내역을 가져오는 데에 실패했습니다: ${e}`));
.catch(e => console.log(`[로그인하기 & 예약 내역 가져오기]에 실패했습니다: ${e}`));

const thoseNeedNoLogin = Promise.all([gettingCafeteria(), fetchingNewNotice()]).catch(e =>
console.log(`카페테리아와 새 공지를 가져오는 데에 실패했습니다: ${e}`),
const thoseNeedNoLogin = Promise.all([
gettingCafeteria(),
fetchingNewNotice(),
fetchOnboardingShownStatus(),
]).catch(e =>
console.log(
`[카페테리아 & 새 공지 & 예약 온보딩 화면 보여주었는지 여부]를 가져오는 데에 실패했습니다: ${e}`,
),
);

await Promise.all([thoseNeedLogin, thoseNeedNoLogin]);
Expand Down

0 comments on commit 1a19d25

Please sign in to comment.