Skip to content

Commit 4458abf

Browse files
authored
Merge pull request #5 from personalrobotics/amaln/web_app_revamp
2023 Web App Revamp
2 parents 257c488 + 7c2fc5b commit 4458abf

File tree

458 files changed

+69293
-92801
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

458 files changed

+69293
-92801
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Describe this pull request. Link to relevant GitHub issues, if any.]
2+
3+
[Explain how this pull request was tested, including but not limited to the below checkmarks.]
4+
5+
***
6+
7+
**Before creating a pull request**
8+
9+
- [ ] Format code with `npm run format`
10+
- [ ] Thoroughly test your code's functionality, including unintended uses.
11+
- [ ] Thoroughly test your code's responsiveness by rendering it on different devices, browsers, etc.
12+
- [ ] Consider the user flow between states that this feature introduces, consider different situations that might occur for the user, and ensure that there is no way for the user to get stuck in a loop.
13+
14+
**Before merging a pull request**
15+
16+
- [ ] Squash all your commits into one (or `Squash and Merge`)

README.md

+2-29
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
# feeding_web_interface
1+
# Feeding Web Interface
22

3-
1. ssh into nano to start the camera node, make sure you export ROS_MASTER_URI to LOVELACE
4-
5-
```ssh [email protected]``` passcode is normal lab passcode, with the last 4 characters changed to N@n0
6-
7-
```export ROS_MASTER_URI=https://192.168.2.145:11311```
8-
9-
```./run_camera.sh```
10-
11-
```uselovelace```
12-
13-
* **Make sure all the following commands must be executed in the src/feeding_web_interface/frontend folder**
14-
15-
2. go to ws/src/feeding_web_interface/frontend
16-
17-
```./ngrok start --all``` to start proxy server
18-
3. launch rosbridge_server to create localhost with the following command
19-
20-
```roslaunch rosbridge_server rosbridge_websocket.launch```
21-
22-
4. enter the following command:
23-
24-
```python -m SimpleHTTPServer 8082```
25-
26-
5. start web video server to help streaming camera node:
27-
28-
```rosrun web_video_server web_video_server```
29-
30-
6. go to webpage http://ada_feeding.ngrok.io/ to see the demo web interface. If you follow the above steps carefully, you should now be able to see the camera stream displayed on the right and the foodImage on left.
3+
This repository contains code for the feeding web app. The app itself is in `feedingwebapp` and contains its own README. The other folder in this repository (will) contain a ROS package that can be used to test the web app's integration with ROS.

feedingwebapp/.eslintignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

feedingwebapp/.eslintrc.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
root: true,
3+
parserOptions: {
4+
ecmaVersion: 2020,
5+
sourceType: 'module',
6+
ecmaFeatures: {
7+
jsx: true
8+
}
9+
},
10+
settings: {
11+
react: {
12+
version: 'detect'
13+
}
14+
},
15+
env: {
16+
jest: true,
17+
browser: true,
18+
amd: true,
19+
node: true
20+
},
21+
extends: [
22+
'eslint:recommended',
23+
'plugin:react/recommended',
24+
'plugin:prettier/recommended' // Make this the last element so prettier config overrides other formatting rules
25+
],
26+
rules: {
27+
'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: false }],
28+
'prettier/prettier': ['error', {}, { usePrettierrc: true }]
29+
}
30+
}

feedingwebapp/.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

feedingwebapp/.prettierrc

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"embeddedLanguageFormatting": "auto",
5+
"htmlWhitespaceSensitivity": "css",
6+
"insertPragma": false,
7+
"jsxBracketSameLine": false,
8+
"jsxSingleQuote": true,
9+
"proseWrap": "preserve",
10+
"quoteProps": "as-needed",
11+
"requirePragma": false,
12+
"semi": false,
13+
"singleQuote": true,
14+
"trailingComma": "none",
15+
"useTabs": false,
16+
"vueIndentScriptAndStyle": false,
17+
"printWidth": 140,
18+
"tabWidth": 2,
19+
"rangeStart": 0
20+
}

feedingwebapp/README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Feeding Web Interface
2+
3+
This directory contains the web app that users use to interact with the robot-assisted feeding system. This readme includes an overview and contribution guidelines, while [TechDocumentation.md](https://github.com/personalrobotics/feeding_web_interface/blob/2023PreDeployment/feedingwebapp/TechDocumentation.md) includes more specific documentation of the technical aspects of the app.
4+
5+
## Overview
6+
The overall user flow for this robot can be seen below.
7+
8+
![newWebAppWorkflow](https://user-images.githubusercontent.com/26337328/223597500-5e520b7a-eb2b-45ad-b9e8-91fec1bdeba4.jpg)
9+
(Last Updated 2023/03/07)
10+
<!-- ![Web App State Machine](https://user-images.githubusercontent.com/8277986/191333326-c71a1765-475c-40f6-87da-a79b7c73e0ee.png)
11+
(Last Updated 2022/09/20) -->
12+
13+
## Dependencies
14+
- [`npm`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
15+
<!-- - [ROS](http://wiki.ros.org/noetic/Installation) -->
16+
17+
## Getting Started
18+
19+
### Installation
20+
1. Clone the repo: `git clone [email protected]:personalrobotics/feeding_web_interface.git` using SSH, or `git clone https://github.com/personalrobotics/feeding_web_interface.git` using HTTPS
21+
2. `cd {PATH TO feeding_web_interface}/feedingwebapp`
22+
3. Install all dependencies: `npm install --legacy-peer-deps`
23+
24+
### Usage
25+
1. `cd {PATH TO feeding_web_interface}/feedingwebapp`
26+
2. Start the app: `npm start`
27+
- Note that if you're not running the robot code alongside the app, set [`debug = true` in `App.jsx`](https://github.com/personalrobotics/feeding_web_interface/blob/b8f5d970628bbaac43b8b9c7dbc4349ada2f32d7/feedingwebapp/src/App.jsx#L17) to be able to move past screens where the app is waiting on the robot. Since the robot is not yet connected, the default is `debug = true`
28+
3. Use a web browser to navigate to `localhost:3000` to see the application.
29+
30+
## Contributing
31+
32+
### Documenting Tasks
33+
34+
All tasks should be tracked and documented as [Github Issues](https://github.com/personalrobotics/feeding_web_interface/issues).
35+
36+
### Adding Dependencies
37+
Note that we use `npm`, not `yarn`, to manage dependencies for this project.
38+
- Dependencies added with `npm install ...` should automatically be added when you add `package.json` and `package-lock.json` to your branch.
39+
- Additional dependencies should be documented in this readme.
40+
41+
### Writing Code
42+
- Generally, only work on code if there is a corresponding [Github Issue](https://github.com/personalrobotics/feeding_web_interface/issues) for it.
43+
- Every feature should be on its own branch, and generally only one person should be pushing to one branch.
44+
- Follow the below style guides:
45+
- [AirBnB React/JSX Style Guide](https://airbnb.io/javascript/react/). This was written before React hooks (e.g, `useState`); see [this for an example of how to order calls to various hooks](https://dev.to/abrahamlawson/react-style-guide-24pp#comment-1f4fd).
46+
- [AirBnB JavaScript Style Guide](https://airbnb.io/javascript/) for anything not covered in the above guide (e.g., variable naming conventions).
47+
- [React Styleguidist guide](https://react-styleguidist.js.org/docs/documenting/) for documenting code. Every function and component should be documented, and within functions there should be enough documentation that someone without knowledge of React can understand it.
48+
- Thoroughly test your feature:
49+
- Run `npm start`, ensure it has no warnings or errors.
50+
- Thoroughly test your feature, including all edge cases, to ensure it works as expected. This includes trying every combination of buttons/actions, even ones we don't expect users to use, to ensure there are no unaccounted for edge cases.
51+
- Ensure the [console](https://developer.chrome.com/docs/devtools/console/) has no errors.
52+
- Thoroughly test responsivity by changing browser/device size to ensure it renders as expected.
53+
- Before creating a Pull Request, run `npm format` and address any warnings or errors.
54+
- Create a Pull Request to merge your branch into `main`. You need at least one approving review to merge.
55+
- Squash all commits on your branch before merging into `main` to ensure a straightforward commit history.

feedingwebapp/TechDocumentation.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Technical Documentation
2+
3+
## Global State vs. Local State
4+
5+
**Local State**: React has the native concept of local state, which exists within a component and triggers re-rendering of the component when changed. Local state should contain the variables that do not need to persist beyond a component (e.g., whether or not a to display a pop-up, countdowns to display within the component, etc.). Use [`useState`](https://react.dev/reference/react/useState) to create and access local state variables; see example [here](https://github.com/personalrobotics/feeding_web_interface/blob/b8f5d970628bbaac43b8b9c7dbc4349ada2f32d7/feedingwebapp/src/Pages/Header/Header.jsx#L22).
6+
7+
**Global State**: Global state are the variables that we need to keep track of across components and page refreshes. This includes what page the app is on (see FAQ below), what stage of the meal the user/robot are currently on, and any settings. All variables in global state should be defined in [`GlobalState.jsx`](https://github.com/personalrobotics/feeding_web_interface/blob/amaln/web_app_revamp/feedingwebapp/src/Pages/GlobalState.jsx), along with their setter functions. Internally, we use [`zustland`](https://github.com/pmndrs/zustand) for global state, which in turn uses cookies to store the state. Therefore, the state will persist across page refreshes, even after clearing the cache. The only way to reset global state is by clearing cookies.
8+
9+
## ROS <--> App Interface (Forthcoming)
10+
11+
## Frequently Asked Questions (FAQ)
12+
13+
Q: Why are we using global state as opposed to a [`Router`](https://www.w3schools.com/react/react_router.asp) to decide which app components to render?
14+
A: If we use a router, each component will have its own URL. That means that by using the "back" button or navigating through the history in their browser, users can reach any screen of the app, even if it doesn't align with the current state of the robot. Since the app's current screen has to be tightly coupled with the state of the robot, we use global state to decide which component to render, as opposed to giving users free reign to jump to any screen of the app by modifying the URL.

0 commit comments

Comments
 (0)