import React, { useEffect, useState } from 'react'; import axios from 'axios'; import { useHistory, Link } from 'react-router-dom'; import moment from 'moment'; import { CircularProgress } from '@material-ui/core'; import IconButton from '@mui/material/IconButton'; import SearchIcon from '@mui/icons-material/Search'; import Notification from '../notification'; import Alert from '../../component/alert'; import InfiniteScroll from "react-infinite-scroll-component"; import { isObject } from 'lodash'; const INFINITE = 5; const SCROLL_DELAY_TIME = 1500; const Search = (props) => { const [notice, setNotice] = useState(localStorage.getItem('notice')); const [keyword, setKeyword] = useState(''); const [tab_status, setTabStatus] = useState(false); const [meeting_list_incomplete, setMeetingListOfIncomplete] = useState([]); const [meeting_list_complete, setMeetingListOfComplete] = useState([]); const [fetch_meeting_list_incomplete, setFetchMeetingListOfIncomplete] = useState([]); const [fetch_meeting_list_complete, setFetchMeetingListOfComplete] = useState([]); const [_success, setSuccess] = useState(''); const [loaded1, setLoaded1] = useState(true); const [loaded2, setLoaded2] = useState(true); const [loaded, setLoaded] = useState(true); const [initPage, setInitPage] = useState(true); useEffect(()=>{ setLoaded(loaded1 && loaded2); },[loaded1, loaded2]) const handleSearch = (e) => { e.preventDefault(); if(keyword == ''){ document.getElementById('keyword').focus(); return; } setLoaded1(false); setLoaded2(false); setInitPage(false); let father_id = document.getElementById('father_id').value; axios.get('/api/fathers/meetings/searchOfIncompleteOfFather', {params:{father_id: father_id, keyword: keyword,}}) .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}) } setMeetingListOfIncomplete(arr); var len = arr.length; if(len > INFINITE) setFetchMeetingListOfIncomplete(arr.slice(0, INFINITE)); else setFetchMeetingListOfIncomplete(arr.slice(0, len)); } }) axios.get('/api/fathers/meetings/searchOfCompleteOfFather', {params:{father_id: father_id, keyword: keyword,}}) .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}) } setMeetingListOfComplete(arr); var len = arr.length; if(len > INFINITE) setFetchMeetingListOfComplete(arr.slice(0, INFINITE)); else setFetchMeetingListOfComplete(arr.slice(0, len)); } }) } const fetchMoreListNonApproval = () => { setTimeout(() => { var x = fetch_meeting_list_incomplete.length; var y = meeting_list_incomplete.length; var c = 0; if(x+INFINITE < y) c = INFINITE; else c = y - x; setFetchMeetingListOfIncomplete(meeting_list_incomplete.slice(0, x+c)); }, SCROLL_DELAY_TIME); }; const fetchMoreListApproval = () => { setTimeout(() => { var x = fetch_meeting_list_complete.length; var y = meeting_list_complete.length; var c = 0; if(x+INFINITE < y) c = INFINITE; else c = y - x; setFetchMeetingListOfComplete(meeting_list_complete.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) .then(response=>{ setNotice(response.data.notice); if(response.data.status_code==200){ if(stateName == "inCompleteOfFather") { const newList = meeting_list_incomplete.map((item) => { if (item.id === meetingId) { const updatedItem = { ...item, is_favorite: currentFavorite == 1 ? 0 : 1, }; return updatedItem; } return item; }); setMeetingListOfIncomplete(newList); setFetchMeetingListOfIncomplete(newList.slice(0, fetch_meeting_list_incomplete.length)); } else { const newList = meeting_list_complete.map((item) => { if (item.id === meetingId) { const updatedItem = { ...item, is_favorite: currentFavorite == 1 ? 0 : 1, }; return updatedItem; } return item; }); setMeetingListOfComplete(newList); setFetchMeetingListOfComplete(newList.slice(0, fetch_meeting_list_complete.length)); } } }) }; return (

ミーティング検索

setKeyword(e.target.value)}/>
{ !loaded && } { loaded && !initPage &&
{ !tab_status &&
} style={{overflow:'none', position:'relative'}} > { fetch_meeting_list_incomplete.length > 0 ? fetch_meeting_list_incomplete?.map((item, id) =>

{ item.title }

{ item.text }

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

データはありません。

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

{ item.title }

{ item.text }

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

データはありません。

}
}
} { _success && setSuccess('')}>{_success} } ) } export default Search;