import React, { useEffect, useState } from 'react'; import { CircularProgress } from '@material-ui/core'; import Notification from '../../component/notification'; import moment from 'moment'; import axios from 'axios'; import { useHistory } from 'react-router-dom' const Favorite = () => { const history = useHistory(); const [loading, setLoading] = useState(true); const [flg, setFlg] = useState(true); const [favorites, setFavorites ] = useState(null); const [others, setOthers ] = useState(null); const fatherId = document.getElementById('father_id').value; useEffect(() => { listOfFavoriteOfFather(); }, []); useEffect(() => { listOfNonFavoriteOfFather(); }, []); function listOfFavoriteOfFather() { axios.get('/api/meetings/listOfFavoriteOfFather', {params: { father_id: fatherId }}).then((response) => { if(response.data.status_code==200){ console.log(response.data.params); setFavorites(response.data.params); } else if(response.data.status_code==400){ //TODO } setLoading(false); }); } function listOfNonFavoriteOfFather() { axios.get('/api/meetings/listOfNonFavoriteOfFather', {params: { father_id: fatherId }}).then((response) => { if(response.data.status_code==200){ console.log(response.data.params); setOthers(response.data.params); } else if(response.data.status_code==400){ //TODO } }); } async function handleFavorite(meetingId, currentFavorite, stateName) { const formdata = new FormData(); formdata.append('meeting_id', meetingId); formdata.append('is_favorite', currentFavorite == 1 ? 0 : 1); axios.post('/api/meetings/registerFavorite', formdata).then((response) => {}) if(stateName == "favorites") { const newList = favorites.map((item) => { if (item.id === meetingId) { const updatedItem = { ...item, is_favorite: currentFavorite == 1 ? 0 : 1, }; return updatedItem; } return item; }); setFavorites(newList); } else { const newList = others.map((item) => { if (item.id === meetingId) { const updatedItem = { ...item, is_favorite: currentFavorite == 1 ? 0 : 1, }; return updatedItem; } return item; }); setOthers(newList); } }; return (