Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyncItemsのIDをUUIDにする #672

Merged
merged 2 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion PeperomiaNative/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Linking from 'expo-linking';
import Constants from 'expo-constants';
import * as SQLite from 'expo-sqlite';
import React, { useState, useCallback, useRef, useEffect } from 'react';
import React, { useState, useCallback, useEffect } from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import EStyleSheet from 'react-native-extended-stylesheet';
import { AppearanceProvider, useColorScheme } from 'react-native-appearance';
Expand Down
16 changes: 11 additions & 5 deletions PeperomiaNative/src/components/pages/MyPage/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import dayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import 'dayjs/locale/ja';
import * as IntentLauncher from 'expo-intent-launcher';
import uuidv4 from 'uuid/v4';
import { RouteProp } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import { RootStackParamList } from 'lib/navigation';
Expand Down Expand Up @@ -98,20 +99,25 @@ class Connected extends Component<ConnectedProps, State> {
try {
const { items, itemDetails, calendars } = await backup();

const uuidList = items.map((item) => ({
from: item.id,
to: uuidv4(),
}));

const request = {
items: items.map((item) => ({
...item,
id: String(item.id),
id: uuidList.find((v) => v.from === item.id)?.to || '',
})),
itemDetails: itemDetails.map((itemDetail) => ({
...itemDetail,
id: String(itemDetail.id),
itemId: String(itemDetail.itemId),
id: uuidv4(),
itemId: uuidList.find((v) => v.from === itemDetail.itemId)?.to || '',
})),
calendars: calendars.map((calendar) => ({
...calendar,
id: String(calendar.id),
itemId: String(calendar.itemId),
id: uuidv4(),
itemId: uuidList.find((v) => v.from === calendar.itemId)?.to || '',
date: dayjs(calendar.date).format(),
})),
};
Expand Down
2 changes: 1 addition & 1 deletion PeperomiaNative/src/components/pages/MyPage/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const MyPage: FC<Props> = (props) => (
</View>
</View>

{Constants.isDevice && (
{!Constants.isDevice && (
<>
<Divider />
<ListItem
Expand Down
4 changes: 2 additions & 2 deletions PeperomiaNative/src/components/pages/Setting/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const SettingPage: FC<Props> = (props) => (
);
})()}

{Constants.isDevice && (
{!Constants.isDevice && (
<ListItem
title="Alexa連携を設定する(β版)"
rightIcon={{
Expand All @@ -134,7 +134,7 @@ const SettingPage: FC<Props> = (props) => (
titleStyle={styles.menuText}
bottomDivider
/>
{Constants.isDevice && (
{!Constants.isDevice && (
<>
<View style={styles.debugSpace} />
<Divider />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ exports[`components/pages/Setting/Page.tsx 正常に表示されている 1`] =
}
title="ユーザー登録 / ログイン"
/>
<Themed.ListItem
bottomDivider={true}
onPress={[MockFunction]}
rightIcon={
Object {
"color": "#333631",
"name": "chevron-right",
}
}
title="Alexa連携を設定する(β版)"
/>
<View />
<Themed.Divider />
<Themed.ListItem
Expand All @@ -95,86 +84,6 @@ exports[`components/pages/Setting/Page.tsx 正常に表示されている 1`] =
}
title="バージョン情報"
/>
<View />
<Themed.Divider />
<Text>
デバッグ機能
</Text>
<Themed.Divider />
<Themed.ListItem
title="UID: test"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[MockFunction]}
rightIcon={
Object {
"color": "#333631",
"name": "chevron-right",
}
}
title="画面表示"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[MockFunction]}
title="初期データ投入"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[MockFunction]}
title="ユーザー初期化"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[MockFunction]}
title="v1.0.0の状態にする"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[MockFunction]}
title="アイテムを削除"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[MockFunction]}
title="DBのデータを表示"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[MockFunction]}
title="firestoreをデータリセット"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[MockFunction]}
title="firestoreをデータを確認"
/>
<Themed.Divider />
<Themed.ListItem
onPress={[Function]}
title="最初のプラン作成キャッシュの削除"
/>
<Themed.Divider />
<Themed.ListItem
bottomDivider={true}
switch={
Object {
"onValueChange": [MockFunction],
"value": false,
}
}
title="使用DBをSQLiteにする"
/>
<Themed.ListItem
onPress={[Function]}
title="Firebase アナリティクス"
/>
<Themed.ListItem
onPress={[Function]}
title="アプリを再起動する"
/>
<Themed.Divider />
</ScrollViewMock>
</View>
`;
36 changes: 25 additions & 11 deletions PeperomiaNative/src/components/pages/SignIn/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Alert } from 'react-native';
import dayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import 'dayjs/locale/ja';
import uuidv4 from 'uuid/v4';
import { RouteProp } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import { RootStackParamList } from 'lib/navigation';
Expand Down Expand Up @@ -64,10 +65,9 @@ const Connected = memo((props: ConnectedProps) => {

if (response.error) {
Alert.alert('ユーザーの保存に失敗しました。');
return false;
}

return true;
return Number(response?.header?.status);
}, [props]);

const backupItem = useCallback(async () => {
Expand All @@ -77,20 +77,25 @@ const Connected = memo((props: ConnectedProps) => {

const { items, itemDetails, calendars } = await backup();

const uuidList = items.map((item) => ({
from: item.id,
to: uuidv4(),
}));

const request = {
items: items.map((item) => ({
...item,
id: String(item.id),
id: uuidList.find((v) => v.from === item.id)?.to || '',
})),
itemDetails: itemDetails.map((itemDetail) => ({
...itemDetail,
id: String(itemDetail.id),
itemId: String(itemDetail.itemId),
id: uuidv4(),
itemId: uuidList.find((v) => v.from === itemDetail.itemId)?.to || '',
})),
calendars: calendars.map((calendar) => ({
...calendar,
id: String(calendar.id),
itemId: String(calendar.itemId),
id: uuidv4(),
itemId: uuidList.find((v) => v.from === calendar.itemId)?.to || '',
date: dayjs(calendar.date).format(),
})),
};
Expand All @@ -110,14 +115,23 @@ const Connected = memo((props: ConnectedProps) => {
return;
}

const ok1 = await saveUser();
const ok2 = await backupItem();
if (ok1 && ok2) {
const httpStatus = await saveUser();
if (httpStatus === 201) {
// ユーザー作成した場合はデータをサーバーに送る
const ok2 = await backupItem();
if (ok2) {
await props.refreshData(uid);
if (onLogin) {
onLogin();
}
}

props.navigation.goBack();
} else if (httpStatus === 200) {
await props.refreshData(uid);
if (onLogin) {
onLogin();
}

props.navigation.goBack();
} else {
// 保存に失敗した時はログアウトさせる
Expand Down