toggleStar() {
        const newState = !this.state.starred;
        this.setState({
            starred: newState
        });

        fetch('/goal/star', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                starred: newState,
                id: this.state.id
            }),
        }).catch(err => console.log(err));

        fetch('/goals/fetch').then((response) => response.json())
            .then((res) => {
                this.props.updateGoals(res.goals);
            }).catch(error => console.warn(error));
    }
// Toggles the star to favorite a post and updates the database
Toggles the star to favorite a post and updates the database
Toggles the star to favorite a post and updates the database
toggleStar() {
        const newState = !this.state.starred;
        this.setState({
            starred: newState
        });
        fetch('/goal/star', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                starred: newState,
                id: this.state.id
            }),
        }).catch(err => console.log(err));
        fetch('/goals/fetch').then((response) => response.json())
            .then((res) => {
                this.props.updateGoals(res.goals);
            }).catch(error => console.warn(error));
    }
toggleStar ( ) { const newState = ! this . state . starred ; this . setState ( { starred : newState } ) ; fetch ( '/goal/star' , { method : 'POST' , headers : { 'Content-Type' : 'application/json' , } , body : JSON . stringify ( { starred : newState , id : this . state . id } ) , } ) . catch ( err => console . log ( err ) ) ; fetch ( '/goals/fetch' ) . then ( ( response ) => response . json ( ) ) . then ( ( res ) => { this . props . updateGoals ( res . goals ) ; } ) . catch ( error => console . warn ( error ) ) ; }
Toggles the star to favorite a post and updates the database
Toggles the star to favorite a post and updates the database