Changeset 13f1472 for frontend/src/FrontPage.js
- Timestamp:
- 09/18/22 18:09:53 (22 months ago)
- Branches:
- master
- Parents:
- 49b0bbd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/FrontPage.js
r49b0bbd r13f1472 2 2 import {Header} from "./Header"; 3 3 import {Link, useNavigate} from "react-router-dom"; 4 import {Button, Card, DatePicker, Form, Image, Input, Modal, notification, Rate, Spin } from "antd";4 import {Button, Card, DatePicker, Form, Image, Input, Modal, notification, Rate, Spin, Upload} from "antd"; 5 5 import placeholderImage from '../src/Assets/placeholder.png' 6 6 import AddNewReservation from "./Dashboard/AddNewReservation"; … … 8 8 import env from "./env"; 9 9 import Review from "./Dashboard/Review"; 10 import {PlusOutlined} from "@ant-design/icons"; 10 11 11 12 const FrontPage = ({user, logout}) => { … … 17 18 const [refreshToggle, setRefreshToggle] = useState(false); 18 19 const history = useNavigate(); 20 const [filteredMenuItems, setFilteredMenuItems] = useState([]); 19 21 20 22 useEffect(()=>{ … … 22 24 axios.get(env.api + 'Restaurants').then(res=>{ 23 25 setRestaurant(res.data); 26 console.log(user); 27 if(!user || !user.isVip){ 28 setFilteredMenuItems(res.data.menu.filter(x => !x.isVipOnly)); 29 }else{ 30 setFilteredMenuItems(res.data.menu.sort((x,y) => x.isVipOnly ? -1 : 1)); 31 } 24 32 setLoading(false); 25 33 }); 26 },[ ])34 },[user]) 27 35 28 36 useEffect(()=>{ … … 33 41 } 34 42 },[user]) 43 44 const updateSearchValue = (value) => { 45 const val = value.target.value.toLowerCase(); 46 setFilteredMenuItems(items=>{ 47 if(val.length==0){ 48 return restaurant.menu; 49 } 50 const its = val.split(' '); 51 let allItems = [] 52 if(!user || !user.isVip){ 53 allItems = [...restaurant.menu.filter(x => !x.isVipOnly)] 54 }else{ 55 allItems = [...restaurant.menu.sort(x => x.isVipOnly)] 56 } 57 for(let it of its){ 58 if(it.length>0) 59 allItems = allItems.filter(x => !x.alergens.includes(it)); 60 } 61 return allItems; 62 }) 63 } 35 64 36 65 const saveNewReview = data =>{ … … 53 82 return( 54 83 <div> 55 <Header onClickButton={!user?()=>history('/login'):logout} buttonText={!user?'Најави се':'Одјави се'} />84 <Header onClickButton={!user?()=>history('/login'):logout} buttonText={!user?'Најави се':'Одјави се'} isVip={user && user.isVip}/> 56 85 {loading ? <Spin style={{margin: 20}}/> : 57 86 <div style={{ … … 105 134 }} > 106 135 <h2 style={{float: 'left'}}>Мени</h2> 136 <Input.Search onChange={updateSearchValue} placeholder={'Филтрирај алергени'} style={{float:'right', width:'200px'}}/> 107 137 </div> 108 {restaurant.menu.map(el => 109 <Card key={el.id} title={el.title} style={{ width: 280, display:'inline-block', margin:'10px' }} size="small"> 138 {filteredMenuItems.map(el => 139 <Card 140 key={el.id} 141 title={el.title} 142 extra={el.isVipOnly ? <span style={{color:'orange',fontWeight:'bold'}}>VIP </span>:''} 143 style={{ width: 280, display:'inline-block', margin:'10px',verticalAlign:'middle' }} 144 size="small" 145 cover={el.image != "data:image/png;base64," ? <img style={{cursor: 'pointer'}} src={el.image} alt="avatar" 146 height='100px' width={'270px'}/> : ''} 147 > 110 148 <p>{el.description}</p> 149 <p>Алергени: {el.alergens.length ==0 ? 'Нема' : el.alergens}</p> 111 150 <b>{el.price} ден.</b> 112 151 </Card>
Note:
See TracChangeset
for help on using the changeset viewer.