Skip to content

Commit

Permalink
feat: add a user context provider to the app (#24)
Browse files Browse the repository at this point in the history
* feat: userContext stuff idk man

* refactor: general all around fixes (removing unused imports, fixing navigation errors)

* refactor: all over the place with this commit, but added swagger docs for file upload

* refactor: make context more general

* refactor: utilize card and popup in the medlist FE
  • Loading branch information
MattCMcCoy authored and andrewcaplan1 committed Feb 6, 2024
1 parent 97ffda1 commit 571f0a8
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 170 deletions.
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 Down Expand Up @@ -91,6 +106,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 Down Expand Up @@ -84,6 +99,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 @@ -23,9 +40,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
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
62 changes: 11 additions & 51 deletions client/App.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
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 CareWalletProvider from './contexts/CareWalletContext';
import { PaperProvider } from 'react-native-paper';

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>
<CareWalletProvider>
<SafeAreaView className="flex-1">
<PaperProvider>
<Router />
</PaperProvider>
</SafeAreaView>
</CareWalletProvider>
);
}
2 changes: 1 addition & 1 deletion client/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: ['nativewind/babel']
plugins: ['react-native-paper/babel', 'nativewind/babel']
};
};
63 changes: 14 additions & 49 deletions client/components/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,27 @@
import { styled } from 'nativewind';
import React from 'react';
import { StyleSheet, View, GestureResponderEvent, Text } from 'react-native';
import { Card } from 'react-native-paper';
import { useNavigation } from '@react-navigation/native';

interface ClickableCardProps {
med: Medication[];
title: string;
onPress: () => void;
children: JSX.Element[] | JSX.Element;
cardStyle?: object;
navigateTo?: string;
children?: JSX.Element[] | JSX.Element;
}

const ClickableCard: React.FC<ClickableCardProps> = ({
med,
const StyledModal = styled(Card.Title, {
props: {
titleStyle: true
}
});

export const ClickableCard: React.FC<ClickableCardProps> = ({
title,
onPress,
children,
cardStyle,
navigateTo
children
}) => {
// const navigation = useNavigation();

const handlePress = () => {
if (navigateTo) {
console.log('trying to navigate!');
// navigation.navigate(navigateTo as never);
} else {
onPress();
}
};

const styles = StyleSheet.create({
card: {
margin: 10,
width: 200,
borderRadius: 8,
borderWidth: 1,
borderColor: 'gray',
backgroundColor: 'lightblue',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.3,
shadowRadius: 3,
elevation: 5
},
title: {
fontSize: 18,
marginBottom: 8,
fontWeight: 'bold'
},
content: {
fontSize: 16,
color: 'gray'
}
});

return (
<Card style={styles.card} onPress={handlePress}>
<Card.Title style={styles.title} title={med[0].medication_name} />
<Card className="m-10 w-64 bg-blue-300" onPress={onPress}>
<Card.Title className="mb-5" title={title} />
<Card.Content>{children}</Card.Content>
</Card>
);
Expand Down
Loading

0 comments on commit 571f0a8

Please sign in to comment.