From a16eda41624691be4f662159de14a5d70ffc624e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=88=E3=83=A9=E3=83=B3=E3=82=AE=E3=83=A3=E3=83=BC?= Date: Fri, 8 Oct 2021 20:41:58 +0700 Subject: [PATCH 1/2] =?UTF-8?q?p=5Faccount=E3=81=A7=E3=81=AF=E3=81=8A?= =?UTF-8?q?=E6=B0=97=E3=81=AB=E5=85=A5=E3=82=8A=E3=81=AE=E5=AE=8C=E4=BA=86?= =?UTF-8?q?=E7=94=BB=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/js/parent/favorite/index.jsx | 155 ++++++++++++------ 1 file changed, 103 insertions(+), 52 deletions(-) diff --git a/backend/resources/js/parent/favorite/index.jsx b/backend/resources/js/parent/favorite/index.jsx index fbfb9666..c8e7f6e6 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
-
- -
+
+
@@ -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">その他 @@ -91,33 +147,31 @@ const Favorite = () => {
    -
  • 3
  • -
  • 4
  • +
  • 0
  • +
  • {item?.approvals.length}
-
    -
  • -
    - name -
    -
  • -
  • -
    - name -
    -
  • -
  • -
    - name -
    -
  • + { item?.approvals.map((v, inx1) => { + return (
  • +
    + name +
    +
  • ); + }) }
- +
); }) :
} @@ -137,33 +191,30 @@ const Favorite = () => {
    -
  • 3
  • -
  • 4
  • +
  • 0
  • +
  • {item?.approvals.length}
-
    -
  • -
    - name -
    -
  • -
  • -
    - name -
    -
  • -
  • -
    - name -
    -
  • + { item?.approvals.map((v, inx2) => { + return (
  • +
    + name +
    +
  • ); + }) }
- + ); }) } From 86f047c4a0fc3e42c68a83bf0e935e9f5ee8c41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=88=E3=83=A9=E3=83=B3=E3=82=AE=E3=83=A3=E3=83=BC?= Date: Fri, 8 Oct 2021 20:46:29 +0700 Subject: [PATCH 2/2] add link --- .../resources/js/parent/favorite/index.jsx | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/resources/js/parent/favorite/index.jsx b/backend/resources/js/parent/favorite/index.jsx index c8e7f6e6..7e429936 100644 --- a/backend/resources/js/parent/favorite/index.jsx +++ b/backend/resources/js/parent/favorite/index.jsx @@ -137,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 }

- + { + e.preventDefault(); + history.push({ + pathname: `/p-account/meeting/detail/${item.id}`, + state: {} + }); + }} >

{ item.title }

{ item.text }