Merge pull request #34 from nakazawakan/feature/p_account_favorite

p_accountではお気に入りの完了画面
このコミットが含まれているのは:
がる 2021-10-18 14:21:09 +09:00 committed by GitHub
コミット 9e07f4040d
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: 4AEE18F83AFDEB23
1個のファイルの変更121行の追加54行の削除

ファイルの表示

@ -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 (
<div className="l-content">
<div className="l-content__ttl">
<div className="l-content__ttl__left">
<h2>お気に入り</h2>
</div>
<div className="p-notification">
<div className="p-notification-icon">
<div className="p-notification-icon-wrap">
<div className="count">1</div>
<div className="p-notification-icon-bg"></div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22.742 19.855" className="icon svg-icon svg-fill svg-y50" ><g fill="none" stroke="#080808" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" data-name="Icon feather-alert-triangle" transform="translate(0.777 0.75)"><path d="M11.188,5.322,2.6,19.659A2.028,2.028,0,0,0,4.334,22.7H21.51a2.028,2.028,0,0,0,1.734-3.042L14.656,5.322a2.028,2.028,0,0,0-3.468,0Z" data-name="パス 3" transform="translate(-2.328 -4.346)"/><path d="M18,13.5v6.91" data-name="パス 4" transform="translate(-7.406 -8.547)"/><path d="M18,25.5h0" data-name="パス 5" transform="translate(-7.406 -11.2)"/></g></svg>
</div>
<div className="p-meetingAdd-btn">
<a
onClick={e => {
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">
<span>ミーティングを追加</span>
<svg version="1.1" viewBox="0 0 500 500" className="icon svg-icon svg-fill svg-up">
<path fill="#000" stroke="none" pid="0" d="M250 437.6c-16.5 0-30-13.5-30-30V280.1H92.5c-16.5 0-30-13.5-30-30s13.5-30 30-30H220V92.6c0-16.5 13.5-30 30-30s30 13.5 30 30v127.5h127.5c16.5 0 30 13.5 30 30s-13.5 30-30 30H280v127.5c0 16.5-13.5 30-30 30z"></path>
</svg>
</a>
</div>
</div>
<Notification />
</div>
<div className="l-content-wrap">
@ -63,6 +117,7 @@ const Favorite = () => {
onClick={e => {
e.preventDefault();
setFlg(true);
listOfFavoriteOfFather();
}}
className={`tab-label ${flg ? "is-active" : ""}`}
htmlFor="tab-01"><span>お気に入り</span></label>
@ -70,6 +125,7 @@ const Favorite = () => {
onClick={e => {
e.preventDefault();
setFlg(false);
listOfNonFavoriteOfFather();
}}
className={`tab-label ${flg ? "" : "is-active"}`}
htmlFor="tab-02"><span>その他</span></label>
@ -81,7 +137,15 @@ const Favorite = () => {
{ !loading ? favorites?.map((item, index) => {
return (
<div className="meeting-item">
<a href="" className="meeting-link">
<a
className="meeting-link"
onClick={e => {
e.preventDefault();
history.push({
pathname: `/p-account/meeting/detail/${item.id}`,
state: {}
});
}} >
<h3 className="meeting-ttl">{ item.title }</h3>
<p className="meeting-txt">{ item.text }</p>
<time dateTime="2021-07-30" className="meeting-time">
@ -91,33 +155,31 @@ const Favorite = () => {
<div className="meeting-member-wrap">
<div data-url="login.html" className="meeting-member-link">
<ul className="meeting-member-count">
<li className="numerator">3</li>
<li className="denominator">4</li>
<li className="numerator">0</li>
<li className="denominator">{item?.approvals.length}</li>
</ul>
<ul className="meeting-member-list" role="list">
<li className="meeting-member__item" role="listitem">
<div className="avatar">
<img alt="name" className="avatar-img" src="../assets/img/avatar/avatar-sample01@2x.png" />
</div>
</li>
<li className="meeting-member__item" role="listitem">
<div className="avatar">
<img alt="name" className="avatar-img" src="../assets/img/avatar/avatar-sample02@2x.png" />
</div>
</li>
<li className="meeting-member__item" role="listitem">
<div className="avatar">
<img alt="name" className="avatar-img" src="../assets/img/avatar/avatar-sample03@2x.png" />
</div>
</li>
{ item?.approvals.map((v, inx1) => {
return (<li className="meeting-member__item" role="listitem">
<div className="avatar">
<img alt="name" className="avatar-img" src={v?.child.image} />
</div>
</li>);
}) }
</ul>
</div>
</div>
</div>
</a>
<button type="button" aria-label="お気に入り" data-tooltip="お気に入り" aria-pressed="false" className="icon a-icon like-icon icon-starFill a-icon-size_medium"></button>
<button
type="button" aria-label="お気に入り" data-tooltip="お気に入り" aria-pressed="false"
onClick={e => {
e.preventDefault();
handleFavorite(item.id, item.is_favorite, 'favorites');
}}
className={`icon a-icon like-icon ${item.is_favorite == 1 ? "icon-starFill" : "icon-star"} a-icon-size_medium`}
></button>
</div>
);
}) : <div style={{position: "relative", left: "50%"}}><CircularProgress /></div>}
@ -127,7 +189,15 @@ const Favorite = () => {
{ others?.length > 0 && others.map((item, index) => {
return (
<div className="meeting-item">
<a href="" className="meeting-link">
<a
className="meeting-link"
onClick={e => {
e.preventDefault();
history.push({
pathname: `/p-account/meeting/detail/${item.id}`,
state: {}
});
}} >
<h3 className="meeting-ttl">{ item.title }</h3>
<p className="meeting-txt">{ item.text }</p>
<time dateTime="2021-07-30" className="meeting-time">
@ -137,33 +207,30 @@ const Favorite = () => {
<div className="meeting-member-wrap">
<div data-url="login.html" className="meeting-member-link">
<ul className="meeting-member-count">
<li className="numerator">3</li>
<li className="denominator">4</li>
<li className="numerator">0</li>
<li className="denominator">{item?.approvals.length}</li>
</ul>
<ul className="meeting-member-list" role="list">
<li className="meeting-member__item" role="listitem">
<div className="avatar">
<img alt="name" className="avatar-img" src="../assets/img/avatar/avatar-sample01@2x.png" />
</div>
</li>
<li className="meeting-member__item" role="listitem">
<div className="avatar">
<img alt="name" className="avatar-img" src="../assets/img/avatar/avatar-sample02@2x.png" />
</div>
</li>
<li className="meeting-member__item" role="listitem">
<div className="avatar">
<img alt="name" className="avatar-img" src="../assets/img/avatar/avatar-sample03@2x.png" />
</div>
</li>
{ item?.approvals.map((v, inx2) => {
return (<li className="meeting-member__item" role="listitem">
<div className="avatar">
<img alt="name" className="avatar-img" src={v?.child.image} />
</div>
</li>);
}) }
</ul>
</div>
</div>
</div>
</a>
<button type="button" aria-label="お気に入り" data-tooltip="お気に入り" aria-pressed="false" className="icon a-icon like-icon icon-star a-icon-size_medium"></button>
<button type="button" aria-label="お気に入り" data-tooltip="お気に入り" aria-pressed="false"
onClick={e => {
e.preventDefault();
handleFavorite(item.id, item.is_favorite, 'others');
}}
className={`icon a-icon like-icon ${item.is_favorite == 1 ? "icon-starFill" : "icon-star"} a-icon-size_medium`}
></button>
</div>
);
}) }