Skip to content

Commit

Permalink
Fixed Profile Page Message Button
Browse files Browse the repository at this point in the history
Cleaned up Navigation
  • Loading branch information
NiketanG committed Apr 22, 2021
1 parent 589ea67 commit 200f51e
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 1,437 deletions.
1,392 changes: 0 additions & 1,392 deletions db_dump.sql

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "instaclone",
"version": "0.0.1",
"private": true,
"author": "NiketanG",
"scripts": {
"android": "react-native run-android",
"android:release": "cd android && ./gradlew assembleRelease && cd ../ && mv android/app/build/outputs/apk/release/app-release.apk build/app-release.apk && adb install build/app-release.apk ",
Expand Down
19 changes: 15 additions & 4 deletions src/app/Routes/ExploreStack.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { NavigationContainer, RouteProp } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { ExploreStackNavigationParams } from "../types/navigation";
import {
ExploreStackNavigationParams,
TabNavigationParams,
} from "../types/navigation";
import Explore from "../Screens/Explore";
import PostDetail from "../Screens/Post";
import ProfilePageStack from "./ProfileStack";
import Comments from "../Screens/Comments";
import { BottomTabNavigationProp } from "@react-navigation/bottom-tabs";

const Stack = createStackNavigator<ExploreStackNavigationParams>();

const ExplorePageStack = () => {
type Props = {
route: RouteProp<TabNavigationParams, "Explore">;
navigation: BottomTabNavigationProp<TabNavigationParams, "Explore">;
};

const ExplorePageStack: React.FC<Props> = ({ route }) => {
return (
<NavigationContainer independent>
<Stack.Navigator headerMode="none" initialRouteName="Explore">
Expand All @@ -19,7 +28,9 @@ const ExplorePageStack = () => {
<Stack.Screen
name="Profile"
component={ProfilePageStack}
initialParams={{ isCurrentUser: false }}
initialParams={{
isCurrentUser: false,
}}
/>
</Stack.Navigator>
</NavigationContainer>
Expand Down
10 changes: 2 additions & 8 deletions src/app/Routes/HomeStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ type Props = {
navigation: BottomTabNavigationProp<TabNavigationParams, "Home">;
};

const HomePageStack: React.FC<Props> = ({ route }) => (
const HomePageStack: React.FC<Props> = () => (
<NavigationContainer independent>
<Stack.Navigator headerMode="none" initialRouteName="Home">
<Stack.Screen
name="Home"
component={Home}
initialParams={{
rootNavigation: route.params.rootNavigation,
}}
/>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Comments" component={Comments} />
<Stack.Screen name="Profile" component={ProfilePageStack} />
</Stack.Navigator>
Expand Down
4 changes: 0 additions & 4 deletions src/app/Routes/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Props = {
route: RouteProp<SwipeTabNavigationParams, "Tabs">;
navigation: MaterialTopTabNavigationProp<SwipeTabNavigationParams, "Tabs">;
};

export const TabNavigation: React.FC<Props> = ({ navigation }) => {
const { colors, dark } = useTheme();
return (
Expand Down Expand Up @@ -59,9 +58,6 @@ export const TabNavigation: React.FC<Props> = ({ navigation }) => {
<Tab.Screen
name="Home"
component={HomePageStack}
initialParams={{
rootNavigation: navigation,
}}
options={{
tabBarIcon: ({ color, focused }) => (
<TabBarIcon
Expand Down
10 changes: 6 additions & 4 deletions src/app/Routes/ProfileStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import EditProfile from "../Screens/Profile/Edit";
import Followers from "../Screens/Profile/Followers";
import Following from "../Screens/Profile/Following";
import PostStack from "./PostStack";
import Messages from "../Screens/Messages/Messages";

type Props = {
route: RouteProp<ProfileStackParams, "ProfilePage">;
Expand All @@ -19,7 +20,7 @@ type Props = {

const Stack = createStackNavigator<ProfileStackParams>();

const ProfilePageStack = (props: Props) => {
const ProfilePageStack: React.FC<Props> = ({ route }) => {
return (
<NavigationContainer independent>
<Stack.Navigator headerMode="none" initialRouteName="ProfilePage">
Expand All @@ -28,28 +29,29 @@ const ProfilePageStack = (props: Props) => {
component={Profile}
initialParams={{
isCurrentUser: true,
...props.route.params,
...route.params,
}}
/>
<Stack.Screen
name="Followers"
component={Followers}
initialParams={{
isCurrentUser: true,
...props.route.params,
...route.params,
}}
/>
<Stack.Screen
name="Following"
component={Following}
initialParams={{
isCurrentUser: true,
...props.route.params,
...route.params,
}}
/>
<Stack.Screen name="Posts" component={PostStack} />
<Stack.Screen name="EditProfile" component={EditProfile} />
<Stack.Screen name="Settings" component={Settings} />
<Stack.Screen name="Messages" component={Messages} />
</Stack.Navigator>
</NavigationContainer>
);
Expand Down
3 changes: 1 addition & 2 deletions src/app/Screens/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const Home: React.FC<Props> = observer(({ route }) => {

const { height } = useWindowDimensions();

const openMessages = () =>
route.params.rootNavigation?.navigate("Messages");
const openMessages = () => {};

const [openedModalData, setOpenedModalData] = useState<{
modalType: "MENU" | "SHARE";
Expand Down
19 changes: 10 additions & 9 deletions src/app/Screens/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ import {
} from "react-native-paper";
import Icon from "react-native-vector-icons/Ionicons";
import { UserAvatar } from "../../Components/UserAvatar";
import {
ExploreStackNavigationParams,
ProfileStackParams,
} from "../../types/navigation";
import { ProfileStackParams } from "../../types/navigation";
import { AppContext } from "../../utils/appContext";
import useUser from "../../utils/useUser";

type Props = {
route: RouteProp<ExploreStackNavigationParams, "Profile">;
route: RouteProp<ProfileStackParams, "ProfilePage">;
navigation: StackNavigationProp<ProfileStackParams, "ProfilePage">;
};

Expand All @@ -49,6 +46,13 @@ const Profile: React.FC<Props> = observer(({ navigation, route }) => {

const { username: savedUsername } = useContext(AppContext);

const openMessage = () => {
if (route.params.username)
navigation.navigate("Messages", {
username: route.params.username,
});
};

const {
user,
posts,
Expand Down Expand Up @@ -288,9 +292,7 @@ const Profile: React.FC<Props> = observer(({ navigation, route }) => {
borderColor: colors.text,
marginTop: 16,
}}
onPress={() =>
navigation.navigate("EditProfile")
}
onPress={openMessage}
>
Message
</Button>
Expand Down Expand Up @@ -372,7 +374,6 @@ const Profile: React.FC<Props> = observer(({ navigation, route }) => {
},
postId: post.postId,
postList: posts,
rootNavigation: navigation,
});
}}
>
Expand Down
23 changes: 9 additions & 14 deletions src/app/types/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ export type SwipeTabNavigationParams = {
Messages: undefined;
};
export type HomeStackNavigationParams = {
Home: {
rootNavigation: MaterialTopTabNavigationProp<
SwipeTabNavigationParams,
"Tabs"
>;
};
Home: undefined;
Comments: CommentsPageParams;
Profile: ProfilePageProps & {
goBack: () => void;
};
};

export type ProfileStackParams = {
ProfilePage: ProfilePageProps;
Messages: {
username: string;
};
ProfilePage: ProfilePageProps & {
goBack?: () => void;
};
Followers: ProfilePageProps & {
followers: Follower[];
};
Expand Down Expand Up @@ -96,21 +96,16 @@ export type PostListParams = {
};
postId: number;
postList: Array<definitions["posts"]>;
rootNavigation: StackNavigationProp<ProfileStackParams, "ProfilePage">;
};

export type PostStackNavigationParams = {
PostList: PostListParams;
Comments: CommentsPageParams;
Profile: StackNavigationProp<ProfileStackParams, "ProfilePage">;
};

export type TabNavigationParams = {
Home: {
rootNavigation: MaterialTopTabNavigationProp<
SwipeTabNavigationParams,
"Tabs"
>;
};
Home: undefined;
Explore: undefined;
// Activity: undefined;
New: undefined;
Expand Down

0 comments on commit 200f51e

Please sign in to comment.