diff --git a/jam-ui/src/components/page/JKPeople-bk.js b/jam-ui/src/components/page/JKPeople-bk.js new file mode 100644 index 000000000..84509c858 --- /dev/null +++ b/jam-ui/src/components/page/JKPeople-bk.js @@ -0,0 +1,147 @@ +import React, { useState, useEffect, useRef } from 'react'; +import PropTypes from 'prop-types'; +import { Alert, Card, CardBody, Col, Row, Button, Form } from 'reactstrap'; +import Loader from '../common/Loader'; +import FalconCardHeader from '../common/FalconCardHeader'; +import { isIterableArray } from '../../helpers/utils'; +import { useTranslation } from 'react-i18next'; + +import { useDispatch, useSelector } from 'react-redux'; +import { fetchPeople } from '../../store/features/peopleSlice'; + +import JKPeopleSearch from './JKPeopleSearch'; +import JKPeopleList from './JKPeopleList'; +import JKPeopleSwiper from './JKPeopleSwiper'; +import { useResponsive } from '@farfetch/react-context-responsive'; + +const JKPeople = ({ className }) => { + const [showSearch, setShowSearch] = useState(false); + const [page, setPage] = useState(1); + const [resetFilter, setResetFilter] = useState(false); + const peopleListRef = useRef(); + const dispatch = useDispatch(); + const { t } = useTranslation(); + + const people = useSelector(state => state.people.people); + const totalPages = useSelector(state => state.people.totalPages); + const loadingStatus = useSelector(state => state.people.status); + + const { greaterThan } = useResponsive(); + + const loadPeople = React.useCallback(() => { + if (totalPages !== 0 && page > totalPages) { + setPage(totalPages + 1); + return; + } + try { + console.log('BEFORE fetching people'); + dispatch(fetchPeople({ page })); + } catch (error) { + console.log('Error fetching people', error); + } + }, [page, totalPages, dispatch]); + + useEffect(() => { + loadPeople(); + }, [page]); + + // useEffect(() => { + // if (loadingStatus === 'succeeded' && peopleListRef.current && page !== 1) { + // } + // }, [loadingStatus]); + + const goNextPage = () => { + setPage(val => ++val); + }; + + const goPrevPage = () => { + if (page > 1) { + setPage(prev => --prev); + } + }; + + const handleScroll = () => { + if (window.innerHeight + window.scrollY >= document.body.offsetHeight) { + goNextPage(); + } + }; + + useEffect(() => { + window.addEventListener('scroll', handleScroll, { passive: true }); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }, []); + + return ( + + + +
+ + +
+
+ + + {loadingStatus === 'loading' && people.length === 0 ? ( + + ) : isIterableArray(people) ? ( + //Start Find Friends table hidden on small screens + <> + {greaterThan.xs ? ( + +
+ + {loadingStatus === 'loading' && people.length !== 0 && loading...} +
+
+ ) : ( + + + + )} + + ) : ( + + + + No Records! + + + + )} +
+
+ ); +}; + +JKPeople.propTypes = { + className: PropTypes.string +}; + +JKPeople.defaultProps = { + className: 'col-6 col-md-4 col-lg-3 col-xxl-2' +}; + +export default JKPeople; diff --git a/jam-ui/src/components/page/JKPeopleFilter.js b/jam-ui/src/components/page/JKPeopleFilter.js new file mode 100644 index 000000000..e0dd39929 --- /dev/null +++ b/jam-ui/src/components/page/JKPeopleFilter.js @@ -0,0 +1,365 @@ +import React, { useState, useEffect } from 'react'; +import { Button, Card, CardBody, Form, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; +import FalconCardHeader from '../common/FalconCardHeader'; +import { useTranslation } from 'react-i18next'; +import Select from 'react-select'; +import JKTooltip from '../common/JKTooltip'; +import PropTypes from 'prop-types'; +import { getGenres, getInstruments } from '../../helpers/rest'; +import { useForm, Controller, useFormState } from 'react-hook-form'; +import { useDispatch } from 'react-redux'; +import { fetchPeople, resetPeople } from '../../store/features/peopleSlice'; +import JKPeople from './JKPeople'; + +function JKPeopleFilter() { + const { t } = useTranslation(); + const [ show, setShow ] = useState(false); + const [resetFilter, setResetFilter] = useState(false); + const [page, setPage] = useState(1); + const [instruments, setInstruments] = useState([]); + const [genres, setGenres] = useState([]); + const dispatch = useDispatch(); + + const { register, handleSubmit, setValue, control } = useForm({ + defaultValues: { + latency_good: true, + latency_fair: true, + latency_high: false, + proficiency_beginner: true, + proficiency_intermediate: true, + proficiency_expert: true, + instruments: [], + genres: [], + joined_within_days: '-1', + active_within_days: '-1' + } + }); + + const { isDirty } = useFormState({ control }); + + const toggle = () => setShow(!show); + + const fetchInstruments = async () => { + await getInstruments() + .then(response => { + if (response.ok) { + return response.json(); + } + }) + .then(data => { + setInstruments( + data.map(instrument => { + return { + value: instrument.id, + label: instrument.description + }; + }) + ); + }) + .catch(error => console.log(error)); + }; + + const fetchGenres = async () => { + await getGenres() + .then(response => { + if (response.ok) { + return response.json(); + } + }) + .then(data => { + setGenres( + data.map(genre => { + return { + value: genre.id, + label: genre.description + }; + }) + ); + }) + .catch(error => { + console.log(error); + }); + }; + + useEffect(() => { + if (resetFilter) { + clearFilterOpts(); + setResetFilter(false); + dispatch(resetPeople()); + handleSubmit(onSubmit)() + } + }, [resetFilter]); + + + const clearFilterOpts = () => { + setValue('latency_good', true) + setValue('latency_fair', true) + setValue('latency_high', false) + setValue('proficiency_beginner', true) + setValue('proficiency_intermediate', true) + setValue('proficiency_expert', true) + setValue('instruments', null) + setValue('genres', null) + setValue('joined_within_days', -1) + setValue('active_within_days', -1) + } + + useEffect(() => { + fetchGenres(); + fetchInstruments(); + }, []); + + const submitForm = event => { + event.preventDefault(); + dispatch(resetPeople()); + handleSubmit(onSubmit)(); + setShow(false); + }; + + const submitPageQuery = page => { + setPage(page) + handleSubmit(onSubmit)() + } + + const onSubmit = data => { + setPage(1) + + let genres = []; + let joined_within_days, + active_within_days = ''; + + if (data.genres) { + genres = data.genres.map(genre => genre.value); + } + if(data.joined_within_days){ + joined_within_days = data.joined_within_days.value; + } + if(data.active_within_days){ + active_within_days = data.active_within_days.value; + } + + const updatedData = { ...data, genres, joined_within_days, active_within_days }; + + try { + dispatch(fetchPeople({ data: updatedData, page: page })); + } catch (error) { + console.log('Error fetching people', error); + } + }; + + const lastActiveOpts = [ + { value: '', label: 'Any Range' }, + { value: '1', label: 'Within Last 1 Days' }, + { value: '7', label: 'Within Last 7 Days' }, + { value: '30', label: 'Within Last 30 Days' }, + { value: '90', label: 'Within Last 90 Days' } + ]; + + const joinedOpts = [ + { value: '', label: 'Any Range' }, + { value: '1', label: 'Within Last 1 Days' }, + { value: '7', label: 'Within Last 7 Days' }, + { value: '30', label: 'Within Last 30 Days' }, + { value: '90', label: 'Within Last 90 Days' } + ]; + + return ( + + +
+ + +
+
+ + + Update Search + +
+
+
+ {/* first column */} +
+
+
+ +
+ setValue('latency_good', e.target.checked)} + /> + +
+
+ setValue('latency_fair', e.target.checked)} + /> + +
+
+ setValue('latency_high', e.target.checked)} + /> + +
+
+ +
+ +
+ setValue('proficiency_beginner', e.target.checked)} + /> + +
+
+ setValue('proficiency_intermediate', e.target.checked)} + /> + +
+
+ setValue('proficiency_expert', e.target.checked)} + /> + +
+
+
+
+ + {/* second column */} +
+ +
+ ( + + )} + /> +
+ +
+ } + /> +
+
+
+
+
+
+ + {' '} + + +
+ +
+
+ ); +} + +JKPeopleFilter.propTypes = { + //show: PropTypes.bool, + //setShow: PropTypes.func + //setPeople: PropTypes.func +}; + +JKPeopleFilter.defaultProps = { + //show: false +}; + +export default JKPeopleFilter;