Skip to content

Commit

Permalink
refactor user module
Browse files Browse the repository at this point in the history
  • Loading branch information
taronaleksanian committed Aug 18, 2024
1 parent a375012 commit 18bf9a7
Show file tree
Hide file tree
Showing 33 changed files with 64 additions and 57 deletions.
5 changes: 2 additions & 3 deletions apps/expo/app/(app)/(drawer)/(tabs)/(stack)/profile/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import React from 'react';
import { Stack } from 'expo-router';
import { useEffect, useState } from 'react';
import { StyleSheet, Text, View, Platform } from 'react-native';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { ProfileScreen, useProfile, useProfileId } from 'app/modules/user';
import Head from 'expo-router/head';
import { useProfile, useProfileId } from 'app/hooks/user';

const Profile = () => {
const [id] = useProfileId();
Expand All @@ -24,7 +23,7 @@ const Profile = () => {
title: userRealName ? `${userRealName}'s Profile` : '',
}}
/>
<ProfileContainer id={id} />
<ProfileScreen userId={id} />
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Platform, ScrollView } from 'react-native';
import { Stack } from 'expo-router';
import Settings from 'app/screens/user/Settings';
import { SettingsScreen } from 'app/modules/user';
import Head from 'expo-router/head';

export default function SettingsPage() {
Expand All @@ -21,7 +21,7 @@ export default function SettingsPage() {
// https://reactnavigation.org/docs/headers#replacing-the-title-with-a-custom-component
}}
/>
<Settings />
<SettingsScreen />
</>
);
}
4 changes: 2 additions & 2 deletions apps/expo/app/(app)/(drawer)/(tabs)/profile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { ProfileScreen } from 'app/modules/user';
import { Platform, ScrollView } from 'react-native';
import { Stack } from 'expo-router';
import Head from 'expo-router/head';
Expand All @@ -21,7 +21,7 @@ export default function Profile() {
// https://reactnavigation.org/docs/headers#replacing-the-title-with-a-custom-component
}}
/>
<ProfileContainer />
<ProfileScreen />
</>
);
}
2 changes: 1 addition & 1 deletion apps/next/pages/profile/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import { StyleSheet, Text, View, Platform } from 'react-native';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { useProfileId } from 'app/hooks/user';
import { useProfileId } from 'app/modules/user';
import { AuthWrapper } from 'app/modules/auth';

// export const runtime = 'experimental-edge'
Expand Down
4 changes: 2 additions & 2 deletions apps/next/pages/profile/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Settings from 'app/screens/user/Settings';
import { SettingsScreen } from 'app/modules/user';
import { AuthWrapper } from 'app/modules/auth';

// export const runtime = 'experimental-edge'

export default function SettingsPage() {
return (
<>
<Settings />
<SettingsScreen />
</>
);
}
Expand Down
5 changes: 2 additions & 3 deletions apps/tauri/src/routes/profile/$id.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { useProfileId } from 'app/hooks/user';
import { ProfileScreen, useProfileId } from 'app/modules/user';

import { createLazyFileRoute } from '@tanstack/react-router';

Expand All @@ -13,7 +12,7 @@ export default function Profile() {

return (
<>
<ProfileContainer id={id} />
<ProfileScreen userId={id} />
</>
);
}
4 changes: 2 additions & 2 deletions apps/tauri/src/routes/profile/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { ProfileScreen } from 'app/modules/user';
import { AuthWrapper } from 'app/modules/auth';
import { createLazyFileRoute } from '@tanstack/react-router';

Expand All @@ -10,7 +10,7 @@ export const Route = createLazyFileRoute('/profile/')({
export default function Profile() {
return (
<AuthWrapper>
<ProfileContainer />
<ProfileScreen />
</AuthWrapper>
);
}
4 changes: 2 additions & 2 deletions apps/tauri/src/routes/profile/settings/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Settings from 'app/screens/user/Settings';
import { SettingsScreen } from 'app/modules/user';
import { AuthWrapper } from 'app/modules/auth';
import { createLazyFileRoute } from '@tanstack/react-router';

Expand All @@ -10,7 +10,7 @@ export const Route = createLazyFileRoute('/profile/settings/')({
export default function SettingsPage() {
return (
<AuthWrapper>
<Settings />
<SettingsScreen />
</AuthWrapper>
);
}
5 changes: 2 additions & 3 deletions apps/vite/src/routes/profile/$id.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { useProfileId } from 'app/hooks/user';
import { ProfileScreen, useProfileId } from 'app/modules/user';

import { createLazyFileRoute } from '@tanstack/react-router';

Expand All @@ -13,7 +12,7 @@ export default function Profile() {

return (
<>
<ProfileContainer id={id} />
<ProfileScreen userId={id} />
</>
);
}
4 changes: 2 additions & 2 deletions apps/vite/src/routes/profile/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { ProfileScreen } from 'app/modules/user';
import { AuthWrapper } from 'app/modules/auth';
import { createLazyFileRoute } from '@tanstack/react-router';

Expand All @@ -10,7 +10,7 @@ export const Route = createLazyFileRoute('/profile/')({
export default function Profile() {
return (
<AuthWrapper>
<ProfileContainer />
<ProfileScreen />
</AuthWrapper>
);
}
4 changes: 2 additions & 2 deletions apps/vite/src/routes/profile/settings/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Settings from 'app/screens/user/Settings';
import { SettingsScreen } from 'app/modules/user';
import { AuthWrapper } from 'app/modules/auth';
import { createLazyFileRoute } from '@tanstack/react-router';

Expand All @@ -10,7 +10,7 @@ export const Route = createLazyFileRoute('/profile/settings/')({
export default function SettingsPage() {
return (
<AuthWrapper>
<Settings />
<SettingsScreen />
</AuthWrapper>
);
}
2 changes: 1 addition & 1 deletion packages/app/components/map/Map.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import * as FileSystem from 'expo-file-system';
import { DOMParser } from 'xmldom';
import { MapProps } from './models';
import { useUserQuery } from 'app/modules/auth';
import { useUpdateUser } from 'app/hooks/user/useUpdateUser';
import { useUpdateUser } from 'app/modules/user';

interface GeoJsonProperties {
name?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/app/modules/auth/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { useGoogleAuth } from './useGoogleAuth';
export { useLogout } from './useLogout';
export { useUserSetter } from './useUserSetter';
export { usePasswordResetToken } from './usePasswordResetToken';
export { useMatchesCurrentUser } from './useMatchesCurrentUser';
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
RLink,
RSkeleton,
} from '@packrat/ui';
import { truncateString } from '../../utils/truncateString';
import { truncateString } from 'app/utils/truncateString';
import { useEditPack } from 'app/modules/pack';
import { Platform } from 'react-native';
import { useEditTrips } from 'app/hooks/trips';
Expand All @@ -35,7 +35,7 @@ interface UserDataCardProps {
isFavorite: boolean;
}

const UserDataCard = ({
export const UserDataCard = ({
type, // "pack" or "trip"
destination,
id,
Expand Down Expand Up @@ -257,5 +257,3 @@ const UserDataCard = ({
</View>
);
};

export default UserDataCard;
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, { useRef, useMemo, useState } from 'react';
import { View, FlatList, Platform } from 'react-native';
import { FeedCard, FeedSearchFilter } from 'app/modules/feed';
import { fuseSearch } from '../../utils/fuseSearch';
import { BaseDialog as OriginalBaseDialog, BaseModal } from '@packrat/ui';
import { fuseSearch } from 'app/utils/fuseSearch';
import { BaseDialog, BaseModal } from '@packrat/ui';
// import BottomSheet from '@gorhom/bottom-sheet';

const BaseDialog: any = OriginalBaseDialog;

interface DataItem {
_id: string;
type: string;
Expand All @@ -16,7 +14,7 @@ interface DataListProps {
data: DataItem[];
}

const DataList = ({ data }: DataListProps) => {
export const UserDataList = ({ data }: DataListProps) => {
const [searchQuery, setSearchQuery] = useState('');
const keys = ['name', 'items.name', 'items.category'];
const options = {
Expand Down Expand Up @@ -107,5 +105,3 @@ const DataList = ({ data }: DataListProps) => {
</>
);
};

export default DataList;
2 changes: 2 additions & 0 deletions packages/app/modules/user/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { UserDataCard } from './UserDataCard';
export { UserDataList } from './UserDetailList';
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export { useGetUser } from './useGetUser';
export { useProfile } from './useProfile';
export { useProfileSettings } from './useProfileSettings';
export { useProfileId } from './useProfileId';
export { useDeleteProfile } from './useDeleteProfile';
export { useUpdateUser } from './useUpdateUser';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { queryTrpc } from '../../trpc';
import { queryTrpc } from 'app/trpc';
import { useAuthUser } from 'app/modules/auth';
import { logoutAuthUser } from 'app/utils/userUtils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { queryTrpc } from '../../trpc';
import { queryTrpc } from 'app/trpc';

export const useGetUser = (userId: string) => {
// If userId is not provided, don’t run the query.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useFetchUserFavorites } from '../favorites';
import { useFetchUserFavorites } from 'app/hooks/favorites';
import { useUserPacks } from 'app/modules/pack';
import { useUserTrips } from '../singletrips';
import { useMatchesCurrentUser } from '../useMatchesCurrentUser';
import { useAuthUser } from 'app/modules/auth';
import { useUserTrips } from 'app/hooks/singletrips';
import { useAuthUser, useMatchesCurrentUser } from 'app/modules/auth';
import { useGetUser } from './useGetUser';

export const useProfile = (id = null) => {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/app/modules/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './hooks';
export * from './screens';
8 changes: 8 additions & 0 deletions packages/app/modules/user/screens/ProfileScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ProfileContainer } from '../widgets';

interface ProfileScreenProps {
userId?: string;
}
export const ProfileScreen = ({ userId }: ProfileScreenProps) => {
return <ProfileContainer id={userId} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RSpinner,
} from '@packrat/ui';
import Avatar from 'app/components/Avatar/Avatar';
import { useProfileSettings } from 'app/hooks/user';
import { useProfileSettings, useDeleteProfile } from '../hooks';
import useTheme from 'app/hooks/useTheme';
import {
userSettingsSchema,
Expand All @@ -26,7 +26,6 @@ import {
} from '@packrat/validations';
import { Platform, View } from 'react-native';
import { useNavigate } from 'app/hooks/navigation';
import { useDeleteProfile } from '../../hooks/user/useDeleteProfile';

const weatherOptions = ['celsius', 'fahrenheit'].map((key) => ({
label: key,
Expand All @@ -38,7 +37,7 @@ const weightOptions = ['lb', 'oz', 'kg', 'g'].map((key) => ({
value: key,
}));

export default function Settings() {
export function SettingsScreen() {
const { user, handleEditUser, handleUpdatePassword } = useProfileSettings();
const { deleteProfile, isLoading } = useDeleteProfile();

Expand Down
2 changes: 2 additions & 0 deletions packages/app/modules/user/screens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ProfileScreen } from './ProfileScreen';
export { SettingsScreen } from './SettingsScreen';
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
RSkeleton,
} from '@packrat/ui';
import { ScrollView } from 'react-native-gesture-handler';
import UserDataContainer from '../../components/user/UserDataContainer';
import useTheme from '../../hooks/useTheme';
import { UserDataContainer } from './UserDataContainer';
import useTheme from '../../../hooks/useTheme';
import { MaterialCommunityIcons } from '@expo/vector-icons';
// import useGetPacks from "../../hooks/useGetPacks";
import { useRouter } from 'app/hooks/router';
import useCustomStyles from 'app/hooks/useCustomStyles';
import Avatar from '../../components/Avatar/Avatar';
import { useProfile } from 'app/hooks/user';
import Avatar from '../../../components/Avatar/Avatar';
import { useProfile } from '../hooks';
import Layout from 'app/components/layout/Layout';

const RText: any = OriginalRText;
Expand Down Expand Up @@ -186,7 +186,7 @@ const SkeletonUserDataCard = () => {
);
};

export default function ProfileContainer({ id = null }) {
export function ProfileContainer({ id = null }) {
const { currentTheme } = useTheme();
const styles = useCustomStyles(loadStyles);
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { RLink } from '@packrat/ui';
import { RStack, RText, RButton, RSkeleton } from '@packrat/ui';
import { VirtualizedList } from 'react-native';
import UserDataCard from './UserDataCard';
import { UserDataCard, UserDataList } from '../components';
import React, { useEffect, useState } from 'react';
import LargeCard from '../card/LargeCard';
import useTheme from '../../hooks/useTheme';
import LargeCard from 'app/components/card/LargeCard';
import useTheme from 'app/hooks/useTheme';
import { hexToRGBA } from 'app/utils/colorFunctions';
import { View } from 'react-native';
import { useAuthUser } from 'app/modules/auth';
import DataList from './UserDetailList';
import Layout from 'app/components/layout/Layout';
import { SearchProvider } from 'app/modules/feed';

Expand All @@ -34,7 +33,7 @@ interface UserDataContainerProps {
SkeletonComponent?: React.ReactElement;
}

export default function UserDataContainer({
export function UserDataContainer({
data = [],
type,
userId,
Expand Down Expand Up @@ -144,7 +143,7 @@ export default function UserDataContainer({
/>

<SearchProvider>
<DataList data={data} />
<UserDataList data={data} />
</SearchProvider>
</>
) : currentUser?.id === userId ? (
Expand Down
2 changes: 2 additions & 0 deletions packages/app/modules/user/widgets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { UserDataContainer } from './UserDataContainer';
export { ProfileContainer } from './ProfileContainer';
2 changes: 1 addition & 1 deletion packages/ui/src/Bento/elements/list/ChatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from 'tamagui';

import useTheme from 'app/hooks/useTheme';
import { useProfileSettings } from 'app/hooks/user';
import { useProfileSettings } from 'app/modules/user';

const List = styled(FlatList<Message>, {
backgroundColor: '$background',
Expand Down

0 comments on commit 18bf9a7

Please sign in to comment.