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

Encapsulated types #76

Merged
merged 1 commit into from
Jan 10, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/frontend/api/auth.ts
Original file line number Diff line number Diff line change
@@ -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/';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/api/index.ts
Original file line number Diff line number Diff line change
@@ -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[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/contexts/Auth.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/navigation/AuthNavigator.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
6 changes: 5 additions & 1 deletion src/frontend/navigation/BottomTabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/navigation/LinkingConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RootStackParamList> = {
prefixes: [Linking.makeUrl('/')],
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/navigation/RootNavigator.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/navigation/StackNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<RootStackParamList>();
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/screens/Auth/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/screens/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions src/frontend/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { MaterialIcons } from '@expo/vector-icons';
import { ColorSchemeName } from 'react-native';

export type ColorScheme = NonNullable<ColorSchemeName>;

export type MaterialIconsOptions = React.ComponentProps<
typeof MaterialIcons
>['name'];
9 changes: 1 addition & 8 deletions src/frontend/types.tsx → src/frontend/types/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@
* https://reactnavigation.org/docs/typescript/
*/

import { MaterialIcons } from '@expo/vector-icons';
import { BottomTabScreenProps } from '@react-navigation/bottom-tabs';
import {
CompositeScreenProps,
NavigatorScreenParams,
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 {
interface RootParamList extends RootStackParamList {}
}
}

export type ColorScheme = NonNullable<ColorSchemeName>;

export type MaterialIconsOptions = React.ComponentProps<
typeof MaterialIcons
>['name'];

export type RootStackParamList = {
Root: NavigatorScreenParams<RootLinkParamList> | undefined;
Modal: undefined;
Expand Down