From 73a453a6c175722dc9d1be32b80eb2f672e2d5b7 Mon Sep 17 00:00:00 2001 From: Inesh Bose <2504266b@student.gla.ac.uk> Date: Mon, 10 Jan 2022 10:40:31 +0000 Subject: [PATCH] Encapsulated types --- src/frontend/api/auth.ts | 2 +- src/frontend/api/index.ts | 2 +- src/frontend/contexts/Auth.tsx | 2 +- src/frontend/navigation/AuthNavigator.tsx | 2 +- src/frontend/navigation/BottomTabNavigator.tsx | 6 +++++- src/frontend/navigation/LinkingConfiguration.ts | 2 +- src/frontend/navigation/RootNavigator.tsx | 2 +- src/frontend/navigation/StackNavigator.tsx | 2 +- src/frontend/screens/Auth/LoginForm.tsx | 2 +- src/frontend/screens/HomePage.tsx | 2 +- src/frontend/{api/types.ts => types/api.ts} | 0 src/frontend/types/index.ts | 8 ++++++++ src/frontend/{types.tsx => types/navigation.ts} | 9 +-------- 13 files changed, 23 insertions(+), 18 deletions(-) rename src/frontend/{api/types.ts => types/api.ts} (100%) create mode 100644 src/frontend/types/index.ts rename src/frontend/{types.tsx => types/navigation.ts} (90%) diff --git a/src/frontend/api/auth.ts b/src/frontend/api/auth.ts index 8285c16..e666648 100644 --- a/src/frontend/api/auth.ts +++ b/src/frontend/api/auth.ts @@ -1,6 +1,6 @@ import axios from 'axios'; import { storeObject, getObject } from './store'; -import { AuthError, AuthToken } from './types'; +import { AuthError, AuthToken } from '../types/api'; import { CLIENT_ID, CLIENT_SECRET } from 'react-native-dotenv'; const TOKEN_URL = 'http://127.0.0.1:8000/api/auth/o/token/'; diff --git a/src/frontend/api/index.ts b/src/frontend/api/index.ts index e30d44c..d23ab9f 100644 --- a/src/frontend/api/index.ts +++ b/src/frontend/api/index.ts @@ -1,6 +1,6 @@ import axios from 'axios'; import { getObject } from './store'; -import { AuthToken, PaginationData, TrackItem } from './types'; +import { AuthToken, PaginationData, TrackItem } from '../types/api'; const list: TrackItem[] = [ { diff --git a/src/frontend/contexts/Auth.tsx b/src/frontend/contexts/Auth.tsx index 8832df6..452b651 100644 --- a/src/frontend/contexts/Auth.tsx +++ b/src/frontend/contexts/Auth.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import { getToken } from '../api/auth'; import { getObject, removeItem } from '../api/store'; -import { AuthToken } from '../api/types'; +import { AuthToken } from '../types/api'; type AuthContextType = { authToken?: AuthToken; diff --git a/src/frontend/navigation/AuthNavigator.tsx b/src/frontend/navigation/AuthNavigator.tsx index 6408899..934428d 100644 --- a/src/frontend/navigation/AuthNavigator.tsx +++ b/src/frontend/navigation/AuthNavigator.tsx @@ -1,6 +1,6 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack'; import * as React from 'react'; -import { RootAuthParamList } from '../types'; +import { RootAuthParamList } from '../types/navigation'; import LoginForm from '../screens/Auth/LoginForm'; import RegisterForm from '../screens/Auth/RegisterForm'; diff --git a/src/frontend/navigation/BottomTabNavigator.tsx b/src/frontend/navigation/BottomTabNavigator.tsx index 3b5842d..88c577d 100644 --- a/src/frontend/navigation/BottomTabNavigator.tsx +++ b/src/frontend/navigation/BottomTabNavigator.tsx @@ -7,7 +7,11 @@ import Colors from '../constants/Colors'; import useColorScheme from '../hooks/useColorScheme'; import HomePage from '../screens/HomePage'; import StatsPage from '../screens/StatsPage'; -import { RootTabParamList, RouteActionIcon, TabConfig } from '../types'; +import { + RootTabParamList, + RouteActionIcon, + TabConfig, +} from '../types/navigation'; import { Text, View } from '../components/Themed'; import { Header, Avatar } from 'react-native-elements'; import JournalPage from '../screens/JournalPage'; diff --git a/src/frontend/navigation/LinkingConfiguration.ts b/src/frontend/navigation/LinkingConfiguration.ts index 1d4c946..a2a3afc 100644 --- a/src/frontend/navigation/LinkingConfiguration.ts +++ b/src/frontend/navigation/LinkingConfiguration.ts @@ -7,7 +7,7 @@ import { LinkingOptions } from '@react-navigation/native'; import * as Linking from 'expo-linking'; -import { RootStackParamList } from '../types'; +import { RootStackParamList } from '../types/navigation'; const linking: LinkingOptions = { prefixes: [Linking.makeUrl('/')], diff --git a/src/frontend/navigation/RootNavigator.tsx b/src/frontend/navigation/RootNavigator.tsx index 8b082f7..df58c6f 100644 --- a/src/frontend/navigation/RootNavigator.tsx +++ b/src/frontend/navigation/RootNavigator.tsx @@ -1,6 +1,6 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack'; import * as React from 'react'; -import { RootLinkParamList } from '../types'; +import { RootLinkParamList } from '../types/navigation'; import BottomTabNavigator from './BottomTabNavigator'; import AuthNavigator from './AuthNavigator'; import { useAuth } from '../contexts/Auth'; diff --git a/src/frontend/navigation/StackNavigator.tsx b/src/frontend/navigation/StackNavigator.tsx index 2d03aa4..15c1f0f 100644 --- a/src/frontend/navigation/StackNavigator.tsx +++ b/src/frontend/navigation/StackNavigator.tsx @@ -2,7 +2,7 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack'; import * as React from 'react'; import ModalScreen from '../screens/ModalScreen'; import NotFoundScreen from '../screens/NotFoundScreen'; -import { RootStackParamList } from '../types'; +import { RootStackParamList } from '../types/navigation'; import RootNavigator from './RootNavigator'; const Stack = createNativeStackNavigator(); diff --git a/src/frontend/screens/Auth/LoginForm.tsx b/src/frontend/screens/Auth/LoginForm.tsx index 321f39a..2efe153 100644 --- a/src/frontend/screens/Auth/LoginForm.tsx +++ b/src/frontend/screens/Auth/LoginForm.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import { Button, Card, Input, Text } from 'react-native-elements'; -import { AuthError } from '../../api/types'; +import { AuthError } from '../../types/api'; import { useAuth } from '../../contexts/Auth'; import { RootAuthScreenProps } from '../../types'; import AuthForm from './AuthForm'; diff --git a/src/frontend/screens/HomePage.tsx b/src/frontend/screens/HomePage.tsx index 459699f..faa05a6 100644 --- a/src/frontend/screens/HomePage.tsx +++ b/src/frontend/screens/HomePage.tsx @@ -8,7 +8,7 @@ import { ComponentTabArguments, ColorScheme } from '../types'; import Colors from '../constants/Colors'; import { IconButtonGroup } from '../components/IconButtonGroup'; import { getTrackItems } from '../api'; -import { PortionItem, TrackItem, UserLog } from '../api/types'; +import { PortionItem, TrackItem, UserLog } from '../types/api'; const frequencyDisplay: { [frequency: number]: string } = { 1: 'd', diff --git a/src/frontend/api/types.ts b/src/frontend/types/api.ts similarity index 100% rename from src/frontend/api/types.ts rename to src/frontend/types/api.ts diff --git a/src/frontend/types/index.ts b/src/frontend/types/index.ts new file mode 100644 index 0000000..6b782a4 --- /dev/null +++ b/src/frontend/types/index.ts @@ -0,0 +1,8 @@ +import { MaterialIcons } from '@expo/vector-icons'; +import { ColorSchemeName } from 'react-native'; + +export type ColorScheme = NonNullable; + +export type MaterialIconsOptions = React.ComponentProps< + typeof MaterialIcons +>['name']; diff --git a/src/frontend/types.tsx b/src/frontend/types/navigation.ts similarity index 90% rename from src/frontend/types.tsx rename to src/frontend/types/navigation.ts index d586a2b..23c1563 100644 --- a/src/frontend/types.tsx +++ b/src/frontend/types/navigation.ts @@ -3,7 +3,6 @@ * https://reactnavigation.org/docs/typescript/ */ -import { MaterialIcons } from '@expo/vector-icons'; import { BottomTabScreenProps } from '@react-navigation/bottom-tabs'; import { CompositeScreenProps, @@ -11,7 +10,7 @@ import { ParamListBase, } from '@react-navigation/native'; import { NativeStackScreenProps } from '@react-navigation/native-stack'; -import { ColorSchemeName } from 'react-native'; +import { ColorScheme, MaterialIconsOptions } from '../types'; declare global { namespace ReactNavigation { @@ -19,12 +18,6 @@ declare global { } } -export type ColorScheme = NonNullable; - -export type MaterialIconsOptions = React.ComponentProps< - typeof MaterialIcons ->['name']; - export type RootStackParamList = { Root: NavigatorScreenParams | undefined; Modal: undefined;