wu-jeffrey / nutrition-tracker-2

https://guarded-headland-90818.herokuapp.com/
0 stars 0 forks source link

Updateable Macro & Calorie Goals #18

Closed wu-jeffrey closed 3 years ago

wu-jeffrey commented 3 years ago

Fixes #17

TASKS:

wu-jeffrey commented 3 years ago

The interdependent / linked sliders implementation with text box is pretty janky but I'm happy that it works.

Also, once the save btn is clicked, the user will be updated, we should cause the auth consumer to refetch the user, so

  1. Here we should move the async API call into it's own function and expose it in the AuthContext, or a reloadUser() fcn that can be called from AuthContext.Consumers e.g. the macroeditor or modal

i.e. here:

  componentDidMount() {
    const token = localStorage.getItem('token');

    const settings = {
      method: 'GET',
      headers: {
        'x-auth-token': localStorage.getItem('token'),
      },
    };

    (async () => {
      const response = await fetch(encodeURI("/api/auth/user"), settings);
      const user = await response.json();

      if (response.status !== 200) {
        this.setState({
          loading: false,
          isAuth: false,
        })
      } else {
        this.setState({
          loading: false, 
          isAuth: true,
          token: token,
          user: user,
        })
      }
    })();
  }