diff --git a/backend/resources/js/parent/favorite/index.jsx b/backend/resources/js/parent/favorite/index.jsx index fbfb9666..7e429936 100644 --- a/backend/resources/js/parent/favorite/index.jsx +++ b/backend/resources/js/parent/favorite/index.jsx @@ -1,5 +1,6 @@ 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' @@ -10,9 +11,18 @@ const Favorite = () => { const [flg, setFlg] = useState(true); const [favorites, setFavorites ] = useState(null); const [others, setOthers ] = useState(null); - + const fatherId = document.getElementById('father_id').value; + useEffect(() => { - axios.get('/api/meetings/listOfFavoriteOfFather', {params: { father_id: 1 }}).then((response) => { + 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); @@ -21,10 +31,10 @@ const Favorite = () => { } setLoading(false); }); - }, []); + } - useEffect(() => { - axios.get('/api/meetings/listOfNonFavoriteOfFather', {params: { father_id: 1 }}).then((response) => { + 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); @@ -32,23 +42,67 @@ const Favorite = () => { //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 (

お気に入り

-
-
-
-
-
1
-
- -
+
+ { + e.preventDefault(); + history.push({ + pathname: '/p-account/meeting/new', + state: {} + }); + }} + data-v-ade1d018="" + className="btn-default btn-yellow btn-meeting btn-shadow btn-r8 btn-h48 btn-fz14"> + ミーティングを追加 + + + +
+
@@ -63,6 +117,7 @@ const Favorite = () => { onClick={e => { e.preventDefault(); setFlg(true); + listOfFavoriteOfFather(); }} className={`tab-label ${flg ? "is-active" : ""}`} htmlFor="tab-01">お気に入り @@ -70,6 +125,7 @@ const Favorite = () => { onClick={e => { e.preventDefault(); setFlg(false); + listOfNonFavoriteOfFather(); }} className={`tab-label ${flg ? "" : "is-active"}`} htmlFor="tab-02">その他 @@ -81,7 +137,15 @@ const Favorite = () => { { !loading ? favorites?.map((item, index) => { return (
- + { + e.preventDefault(); + history.push({ + pathname: `/p-account/meeting/detail/${item.id}`, + state: {} + }); + }} >

{ item.title }

{ item.text }

- +
); }) :
} @@ -127,7 +189,15 @@ const Favorite = () => { { others?.length > 0 && others.map((item, index) => { return (
- + { + e.preventDefault(); + history.push({ + pathname: `/p-account/meeting/detail/${item.id}`, + state: {} + }); + }} >

{ item.title }

{ item.text }

- +
); }) }