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

feat: add a user context provider to the app #24

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
43 changes: 42 additions & 1 deletion backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@ const docTemplate = `{
"file"
],
"summary": "Upload a file",
"parameters": [
{
"type": "file",
"description": "Body with file zip",
"name": "file_data",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
"description": "OK",
"schema": {
"$ref": "#/definitions/models.File"
}
},
"400": {
"description": "Bad Request"
}
}
}
Expand All @@ -51,6 +66,32 @@ const docTemplate = `{
}
},
"definitions": {
"models.File": {
"type": "object",
"properties": {
"file_id": {
"type": "integer"
},
"file_name": {
"type": "string"
},
"file_size": {
"type": "integer"
},
"group_id": {
"type": "integer"
},
"task_id": {
"type": "integer"
},
"upload_by": {
"type": "integer"
},
"upload_date": {
"type": "string"
}
}
},
"models.Medication": {
"type": "object",
"properties": {
Expand Down
43 changes: 42 additions & 1 deletion backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@
"file"
],
"summary": "Upload a file",
"parameters": [
{
"type": "file",
"description": "Body with file zip",
"name": "file_data",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
"description": "OK",
"schema": {
"$ref": "#/definitions/models.File"
}
},
"400": {
"description": "Bad Request"
}
}
}
Expand All @@ -44,6 +59,32 @@
}
},
"definitions": {
"models.File": {
"type": "object",
"properties": {
"file_id": {
"type": "integer"
},
"file_name": {
"type": "string"
},
"file_size": {
"type": "integer"
},
"group_id": {
"type": "integer"
},
"task_id": {
"type": "integer"
},
"upload_by": {
"type": "integer"
},
"upload_date": {
"type": "string"
}
}
},
"models.Medication": {
"type": "object",
"properties": {
Expand Down
27 changes: 27 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
basePath: /
definitions:
models.File:
properties:
file_id:
type: integer
file_name:
type: string
file_size:
type: integer
group_id:
type: integer
task_id:
type: integer
upload_by:
type: integer
upload_date:
type: string
type: object
models.Medication:
properties:
medication_id:
Expand All @@ -16,9 +33,19 @@ paths:
/files/upload:
post:
description: Upload a file to database and S3 bucket
parameters:
- description: Body with file zip
in: formData
name: file_data
required: true
type: file
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.File'
"400":
description: Bad Request
summary: Upload a file
tags:
- file
Expand Down
7 changes: 5 additions & 2 deletions backend/schema/files/routes.go
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding a file input into swagger for file upload

Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ func GetFileGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup {
// @summary Upload a file
// @description Upload a file to database and S3 bucket
// @tags file
// @success 200
// @param file_data formData file true "Body with file zip"
//
// @success 200 {object} models.File
// @failure 400
// @router /files/upload [post]
func (pg *PgModel) UploadFileRoute(c *gin.Context) {
// TODO: Ensure Swagger Knows about there bad request returns!!!
// TODO: Ensure Swagger Knows about the bad request returns!!!
var file models.File

if err := c.Bind(&file); err != nil {
Expand Down
59 changes: 8 additions & 51 deletions client/App.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically cleanup, but also adding context and paper provider so everywhere has access to RNP and our group and user context

Original file line number Diff line number Diff line change
@@ -1,57 +1,14 @@
import * as React from 'react';
import { Text } from 'react-native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { NavigationContainer, NavigationProp } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import LoginPage from './screens/Login';
import MedList from './screens/Medication';
import Home from './assets/home.svg';
import DocPickerButton from './components/DocPickerButton';
import { SafeAreaView } from 'react-native-safe-area-context';
import Router from './navigation/Router';
import UserContext from './contexts/userContext';

export type ScreenNames = ['BottomNav', 'Landing', 'TEMP-FileUpload', 'Login'];
export type RootStackParamList = Record<ScreenNames[number], any>;
export type StackNavigation = NavigationProp<RootStackParamList>;

const Stack = createNativeStackNavigator<RootStackParamList>();
const Tab = createBottomTabNavigator();

// TODO: figure out a way to do this better, I didnt enjoy this way of doing it in SaluTemp there HAS to be a better way
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Login"
options={{ headerShown: true }}
component={LoginPage}
/>
<Stack.Screen
name="BottomNav"
options={{ headerShown: false }}
component={Tabs}
/>
<Stack.Screen
name="TEMP-FileUpload"
options={{ headerShown: true }}
component={DocPickerButton}
/>
</Stack.Navigator>
</NavigationContainer>
);
}

function Tabs() {
return (
<Tab.Navigator>
<Tab.Screen
name="Landing"
options={{
headerShown: true,
tabBarIcon: () => <Home color={'gray'} />,
tabBarLabel: () => <Text>Landing</Text>
}}
component={MedList}
/>
</Tab.Navigator>
<UserContext>
<SafeAreaView className="flex-1">
<Router />
</SafeAreaView>
</UserContext>
);
}
4 changes: 2 additions & 2 deletions client/components/Card.tsx
Copy link
Contributor Author

@MattCMcCoy MattCMcCoy Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

figured out how to get tailwind to work in RNP lol

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { StyleSheet, View, GestureResponderEvent, Text } from 'react-native';
import { StyleSheet } from 'react-native';
import { Card } from 'react-native-paper';
import { useNavigation } from '@react-navigation/native';
import { Medication } from '../types/medication';

interface ClickableCardProps {
med: Medication[];
Expand Down
1 change: 1 addition & 0 deletions client/components/PopupModal.tsx
Copy link
Contributor Author

@MattCMcCoy MattCMcCoy Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

figured out how to get tailwind to work in RNP lol

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Button,
Provider as PaperProvider
} from 'react-native-paper';
import { Medication } from '../types/medication';

interface PopupModalProps {
med: Medication[];
Expand Down
45 changes: 45 additions & 0 deletions client/contexts/userContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { createContext, useContext, useEffect, useState } from 'react';
import { getAuth, onAuthStateChanged } from 'firebase/auth';
import { User } from '../types/user';

type UserContextData = {
user: User;
};

const UserContext = createContext({} as UserContextData);

// TODO: Add Group ID, and User Role to this.
// TODO: Should maybe be a group prop and not inside user.
// TODO: make name more generic
export default function UserProvider({ children }: { children: any }) {
const [user, setUser] = useState({} as User);
const auth = getAuth();

useEffect(() => {
onAuthStateChanged(auth, (user) => {
const signedInUser: User = {
userID: user?.uid ?? '',
userEmail: user?.email ?? ''
};
setUser(signedInUser);
});
}, []);

const UserStore: UserContextData = {
user: user
};

return (
<UserContext.Provider value={UserStore}>{children}</UserContext.Provider>
);
}

export const useUser = (): UserContextData => {
const context = useContext(UserContext);

if (!context) {
throw new Error('useUser must be used within a UserProvider');
}

return context;
};
28 changes: 28 additions & 0 deletions client/navigation/AppNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { NavigationProp } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import LoginPage from '../screens/Login';
import AppStackBottomTabNavigator from './BottomTabNavigator';

export type AppScreenNames = ['BottomNavScreens', 'Landing', 'Login'];
type AppStackParamList = Record<AppScreenNames[number], any>;

export type AppStackNavigation = NavigationProp<AppStackParamList>;
const AppStack = createNativeStackNavigator<AppStackParamList>();

export default function AppNavigation() {
return (
<AppStack.Navigator>
<AppStack.Screen
name="Login"
options={{ headerShown: true }}
component={LoginPage}
/>
<AppStack.Screen
name="BottomNavScreens"
options={{ headerShown: false }}
component={AppStackBottomTabNavigator}
/>
</AppStack.Navigator>
);
}
23 changes: 23 additions & 0 deletions client/navigation/BottomTabNavigator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import React from 'react';
import MedList from '../screens/Medication';
import { Text } from 'react-native';
import Home from '../assets/home.svg';

const AppStackBottomTab = createBottomTabNavigator();

export default function AppStackBottomTabNavigator() {
return (
<AppStackBottomTab.Navigator>
<AppStackBottomTab.Screen
name="Landing"
options={{
headerShown: true,
tabBarIcon: () => <Home color={'gray'} />,
tabBarLabel: () => <Text>Landing</Text>
}}
component={MedList}
/>
</AppStackBottomTab.Navigator>
);
}
11 changes: 11 additions & 0 deletions client/navigation/Router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import AppNavigation from './AppNavigation';

export default function Router() {
return (
<NavigationContainer>
<AppNavigation />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im thinking if onboarding ever gets added it can be its own nav stack. Or if we ever want to have another nav stack can also be separated here

</NavigationContainer>
);
}
Loading
Loading