import React, { useRef, useEffect, useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import moment from 'moment'; import Notification from '../../component/notification'; import Alert from '../../component/alert'; import PageLoader from '../../component/page_loader'; import InfiniteScroll from "react-infinite-scroll-component"; const INFINITE = 10; const SCROLL_DELAY_TIME = 1500; const ParentFavorite = () => { const location = useLocation(); const [notice, setNotice] = useState(localStorage.getItem('notice')); const father_id = localStorage.getItem('kiki_acc_id'); const [tab_status, setTabStatus] = useState(false); const [loaded, setLoaded] = useState(false); const [loaded1, setLoaded1] = useState(false); const [loaded2, setLoaded2] = useState(false); const [meeting_list_non_favorite, setMeetingListOfNonFavorite] = useState([]); const [meeting_list_favorite, setMeetingListOfFavorite] = useState([]); const [fetch_meeting_list_non_favorite, setFetchMeetingListOfNonFavorite] = useState([]); const [fetch_meeting_list_favorite, setFetchMeetingListOfFavorite] = useState([]); const [_success, setSuccess] = useState(location.state); const [_400error, set400Error] = useState(''); const isMountedRef = useRef(true); useEffect(()=>{ setLoaded(loaded1 && loaded2); },[loaded1, loaded2]) useEffect(async () => { isMountedRef.current = false; setLoaded(false); await axios.get('/api/fathers/meetings/listOfNonFavoriteOfFather', {params:{father_id: father_id}}) .then(response => { setLoaded1(true); setNotice(response.data.notice); if(response.data.status_code==200){ var list = response.data.params; var arr = []; for(var i in list){ var total=0, num=0; for(var j in list[i].approvals) { if(list[i].approvals[j].approval_at) num ++; total ++; } arr.push({...list[i], denominator:total, numerator:num}) } setMeetingListOfNonFavorite(arr); var len = arr.length; if(len > INFINITE) setFetchMeetingListOfNonFavorite(arr.slice(0, INFINITE)); else setFetchMeetingListOfNonFavorite(arr.slice(0, len)); } else { set400Error("失敗しました。"); } }) await axios.get('/api/fathers/meetings/listOfFavoriteOfFather', {params:{father_id: father_id}}) .then(response => { setLoaded2(true); setNotice(response.data.notice); if(response.data.status_code==200){ var list = response.data.params; var arr = []; for(var i in list){ var total=0, num=0; for(var j in list[i].approvals) { if(list[i].approvals[j].approval_at) num ++; total ++; } arr.push({...list[i], denominator:total, numerator:num}) } setMeetingListOfFavorite(arr); var len = arr.length; if(len > INFINITE) setFetchMeetingListOfFavorite(arr.slice(0, INFINITE)); else setFetchMeetingListOfFavorite(arr.slice(0, len)); } else { set400Error("失敗しました。"); } }) },[]); const fetchMoreListOfNonFavorite = () => { setTimeout(() => { var x = fetch_meeting_list_non_favorite.length; var y = meeting_list_non_favorite.length; var c = 0; if(x+INFINITE < y) c = INFINITE; else c = y - x; setFetchMeetingListOfNonFavorite(meeting_list_non_favorite.slice(0, x+c)); }, SCROLL_DELAY_TIME); }; const fetchMoreListOfFavorite = () => { setTimeout(() => { var x = fetch_meeting_list_favorite.length; var y = meeting_list_favorite.length; var c = 0; if(x+INFINITE < y) c = INFINITE; else c = y - x; setFetchMeetingListOfFavorite(meeting_list_favorite.slice(0, x+c)); }, SCROLL_DELAY_TIME); }; 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/fathers/meetings/registerFavorite', formdata) if(stateName == "nonFavoriteOfFather") { const newList = meeting_list_non_favorite.map((item) => { if (item.id === meetingId) { const updatedItem = { ...item, is_favorite: item.is_favorite == 1 ? 0 : 1, }; return updatedItem; } return item; }); setMeetingListOfNonFavorite(newList); setFetchMeetingListOfNonFavorite(newList.slice(0, fetch_meeting_list_non_favorite.length)); } else { const newList = meeting_list_favorite.map((item) => { if (item.id === meetingId) { const updatedItem = { ...item, is_favorite: item.is_favorite == 1 ? 0 : 1, }; return updatedItem; } return item; }); setMeetingListOfFavorite(newList); setFetchMeetingListOfFavorite(newList.slice(0, fetch_meeting_list_favorite.length)); } }; return (

お気に入り

ミーティングを追加
{ !loaded && } { loaded &&
{ !tab_status &&
} style={{overflow:'none', position:'relative'}} > { fetch_meeting_list_favorite.length > 0 ? fetch_meeting_list_favorite?.map((item, id) =>

{ item.title }

{ item.text }

  • {item.numerator}
  • {item.denominator}
    { item.approvals?.map((v, inx1) => { if(v.approval_at) return(
  • name
  • ) }) }
) :

データはありません。

}
} { tab_status &&
} style={{overflow:'none', position:'relative'}} > { fetch_meeting_list_non_favorite.length > 0 ? fetch_meeting_list_non_favorite?.map((item, id) =>

{ item.title }

{ item.text }

  • {item.numerator}
  • {item.denominator}
    { item.approvals?.map((v, inx1) => { if(v.approval_at) return(
  • name
  • ) }) }
) :

データはありません。

}
}
} { _success && setSuccess('')}>{_success} } { _400error && set400Error('')}>{_400error} } ) } export default ParentFavorite;