Skip to content

Commit

Permalink
Merge pull request #71 from dave-b-b/fix-frontend
Browse files Browse the repository at this point in the history
Fix frontend
  • Loading branch information
dave-b-b authored Aug 16, 2024
2 parents 3c8d218 + b752951 commit 8acd50b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
16 changes: 7 additions & 9 deletions src/components/LandingComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from "react";
import {useContext, useEffect} from "react";
import { Container } from "react-bootstrap";
import ExpensesTable from "./ExpensesTable.jsx";
import CategoryModal from "./CategoryModal.jsx";
Expand All @@ -12,21 +12,19 @@ import achievementConfig from "../config/achievementConfig.js";
import '../App.css';

const LandingComponent = () => {
const { setScreen, ocrData, serverResponse, setServerResponse } = useContext(AppContext);
const user = new User(JSON.parse(localStorage.getItem('user')))
const { setScreen, ocrData, serverResponse, setServerResponse, user } = useContext(AppContext);
const renderNewScreen = (screen) => {
if (screen === undefined) {
return;
}
setScreen(screen);
};

const handleSubmit = async () => {
// const userWithUpdates = new User(user);
// userWithUpdates.transactions.push(ocrData);
// const result = await user.updateFirebase();
// setServerResponse(result);
};
useEffect(() => {
if (serverResponse) {
setServerResponse(null);
}
}, [user]);

return (
<AchievementProvider config={achievementConfig} initialState={user.serialize()} badgesButtonPosition={'top-right'}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Login = () => {
localStorage.setItem('user', user)
setScreen("landing")
} catch (err) {
console.error(err);
console.log(err);
}
};

Expand Down
12 changes: 3 additions & 9 deletions src/context/AppContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import FormData from "../models/FormData.js"
import User from "../models/User.js"


const AppContext = createContext();
const AppContext = createContext({});

const AppProvider = ({ children }) => {

Expand All @@ -16,11 +16,7 @@ const AppProvider = ({ children }) => {
}

const [screen, setScreen] = useState();
const [user, setUser] = useState({
first_name: '',
last_name: '',
categories: []
});
const [user, setUser] = useState(new User(JSON.parse(localStorage.getItem('user'))));
const [modalIsOpen, setModalIsOpen] = useState(true);
const [show, setShow] = useState(false);
const [capturedPhoto, setCapturedPhoto] = useState(null);
Expand All @@ -32,9 +28,7 @@ const AppProvider = ({ children }) => {

// updating user data based on state
const fetchUserData = async () => {
const endpoint = import.meta.env.MODE === 'development'
? import.meta.env.VITE_DEV_GET_USER_ENDPOINT
: import.meta.env.VITE_PROD_GET_USER_ENDPOINT;
const endpoint = import.meta.env.VITE_DEV_GET_USER_ENDPOINT;

try {
const response = await fetch(endpoint);
Expand Down

0 comments on commit 8acd50b

Please sign in to comment.