-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
159 lines (149 loc) · 5.46 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import React from "react";
import { StatusBar, useColorScheme } from "react-native";
import { ActionSheetProvider } from "@expo/react-native-action-sheet";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { observer } from "mobx-react-lite";
import { SafeAreaProvider } from "react-native-safe-area-context";
import AddAccount from "./Screens/AddAccount";
import BlocksScreen from "./Screens/Blocks/BlocksScreen";
import CommentWrite from "./Screens/CommentWrite/CommentWrite";
import CommunityScreen from "./Screens/Community/CommunityScreen";
import DebugScreen from "./Screens/DebugScreen";
import HomeScreen from "./Screens/HomeScreen";
import LoginScreen from "./Screens/LoginScreen";
import PostScreen from "./Screens/Post/PostScreen";
import PostWrite from "./Screens/PostWrite";
import Behavior from "./Screens/Settings/Behavior";
import Looks from "./Screens/Settings/Looks";
import ProfileSettings from "./Screens/Settings/ProfileSettings";
import SettingsScreen from "./Screens/SettingsScreen";
import MessageWrite from "./Screens/Unreads/MessageWrite";
import UserScreen from "./Screens/User/UserScreen";
import { Icon } from "./ThemedComponents";
import { AppAmoledTheme, AppDarkTheme, AppTheme } from "./commonStyles";
import Prompt from "./components/Prompt";
import { ReportMode, apiClient } from "./store/apiClient";
import { Theme, preferences } from "./store/preferences";
const Stack = createNativeStackNavigator();
const App = observer(() => {
const scheme = useColorScheme();
const systemTheme = scheme === "dark" ? AppDarkTheme : AppTheme;
const isLightStatusBar =
preferences.theme === Theme.System
? scheme !== "dark"
: preferences.theme === Theme.Light;
const schemeMap = {
[Theme.System]: systemTheme,
[Theme.Light]: AppTheme,
[Theme.Dark]: AppDarkTheme,
[Theme.Amoled]: AppAmoledTheme,
};
const sendReport = (text: string) => {
if (apiClient.reportMode === ReportMode.Post) {
apiClient.api
.createPostReport({
post_id: apiClient.reportedItemId,
reason: text,
})
.then(() => {
closeReport();
});
} else {
apiClient.api
.createCommentReport({
comment_id: apiClient.reportedItemId,
reason: text,
})
.then(() => {
closeReport();
});
}
};
const closeReport = () => {
apiClient.setShowPrompt(false);
};
const reportMode = apiClient.reportMode;
const promptActions =
reportMode !== ReportMode.Off
? {
onCancel: closeReport,
onConfirm: sendReport,
}
: apiClient.promptActions;
return (
<SafeAreaProvider style={{ flex: 1 }}>
{/* I don't really remember how it works */}
<StatusBar
barStyle={isLightStatusBar ? "dark-content" : "light-content"}
backgroundColor={schemeMap[preferences.theme].colors.card}
/>
<ActionSheetProvider>
<NavigationContainer theme={schemeMap[preferences.theme]}>
<Stack.Navigator initialRouteName={"Home"}>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Post"
component={PostScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
options={{ headerTitle: "New Comment" }}
name={"CommentWrite"}
component={CommentWrite}
/>
<Stack.Screen
options={{ headerTitle: "New Post" }}
name={"PostWrite"}
component={PostWrite}
/>
<Stack.Screen
options={{ headerTitle: "Message" }}
name={"MessageWrite"}
component={MessageWrite}
/>
<Stack.Screen
options={{
headerRight: () => <Icon name={"arrow-up"} size={24} />,
}}
name="Community"
component={CommunityScreen}
/>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen
options={{ headerTitle: "Add Account" }}
name={"AddAccount"}
component={AddAccount}
/>
<Stack.Screen name="User" component={UserScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} />
<Stack.Screen name="Debug" component={DebugScreen} />
<Stack.Screen name="Blocks" component={BlocksScreen} />
<Stack.Screen name="Looks" component={Looks} />
<Stack.Screen name="Behavior" component={Behavior} />
<Stack.Screen name="ProfileSettings" component={ProfileSettings} />
</Stack.Navigator>
{apiClient.showPrompt ? (
<Prompt
text={`Describe whats wrong with this ${
reportMode === ReportMode.Post ? "post" : "comment"
}`}
title={`Report ${
reportMode === ReportMode.Post ? "post" : "comment"
}`}
reportMode={reportMode}
placeholder={"Type a reason here"}
onSubmit={promptActions.onConfirm}
onCancel={promptActions.onCancel}
/>
) : null}
</NavigationContainer>
</ActionSheetProvider>
</SafeAreaProvider>
);
});
export default App;