mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Feature/tinder (#179)
* basic framework for match/tinder * working version of swiping * working version of profile editing * introducing backend * working matching system * working profile updating * fix all linting issues * updated events to Enum * working profile generation * documentation updates * general PR feedback * working profile loading, matches show matchedAt * slight modification to event strings * added sql imports
This commit is contained in:
46 files changed
+1932
-49
No files matched your search
@@ -0,0 +1,163 @@
|
||||
import React, { useState, useRef } from 'react';
|
||||
import { Card, Fab, Box, Tooltip } from '@material-ui/core';
|
||||
import CancelIcon from '@material-ui/icons/Clear';
|
||||
import FireIcon from '@material-ui/icons/Whatshot';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { FormattedProfile } from '../../../../../typings/match';
|
||||
import Draggable from './Draggable';
|
||||
import StatusDisplay from './StatusDisplay';
|
||||
import Profile from './profile/Profile';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
position: 'absolute',
|
||||
margin: '15px 15px 25px 15px',
|
||||
height: 'calc(100% - 90px)',
|
||||
width: 'calc(100% - 30px)',
|
||||
overflow: 'hidden',
|
||||
cursor: 'pointer',
|
||||
},
|
||||
media: {
|
||||
height: '60%',
|
||||
},
|
||||
content: {
|
||||
height: '40%',
|
||||
},
|
||||
status: {
|
||||
position: 'absolute',
|
||||
zIndex: 20,
|
||||
padding: '5px 15px',
|
||||
top: 40,
|
||||
fontSize: '28px',
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
statusVisible: {
|
||||
transition: 'opacity 0.25s ease-in-out',
|
||||
},
|
||||
// when a user swipes on a profile we need to hide the transition
|
||||
// otherwise the status will be transitioning out when the next
|
||||
// profile shows up
|
||||
statusNull: {
|
||||
transition: 'opacity 0s',
|
||||
},
|
||||
like: {
|
||||
color: 'green',
|
||||
border: '6px solid green',
|
||||
left: 30,
|
||||
transform: 'rotate(-18deg)',
|
||||
},
|
||||
nope: {
|
||||
color: 'red',
|
||||
border: '6px solid red',
|
||||
right: 30,
|
||||
transform: 'rotate(18deg)',
|
||||
},
|
||||
buttons: {
|
||||
position: 'absolute',
|
||||
bottom: '3px',
|
||||
width: '100%',
|
||||
height: '55px',
|
||||
},
|
||||
button: {
|
||||
margin: '0px 15px',
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
profile: FormattedProfile;
|
||||
onSwipe: (id: number, liked: boolean) => void;
|
||||
}
|
||||
|
||||
// this represents how far from the original mouse
|
||||
// click a user has to drag the profile in order for
|
||||
// it to be registered as a like or dislike
|
||||
const DECISION_THRESHOLD_X_px = 150;
|
||||
|
||||
const ActiveProfile = ({ profile, onSwipe }: IProps) => {
|
||||
const c = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [status, setStatus] = useState(null);
|
||||
const statusRef = useRef(null);
|
||||
const idRef = useRef(null);
|
||||
|
||||
// we are reading mutated state from the Draggable element so we
|
||||
// keep track of it using a ref. Without this ref it will appear
|
||||
// from React's point of view that the state is not updating
|
||||
statusRef.current = status;
|
||||
idRef.current = profile.id;
|
||||
|
||||
function onDrag(deltaX: number): void {
|
||||
const hasDecision = status !== null;
|
||||
if (!hasDecision && deltaX > DECISION_THRESHOLD_X_px) {
|
||||
setStatus(true);
|
||||
} else if (!hasDecision && deltaX < -DECISION_THRESHOLD_X_px) {
|
||||
setStatus(false);
|
||||
} else if (deltaX > -DECISION_THRESHOLD_X_px && deltaX < DECISION_THRESHOLD_X_px) {
|
||||
setStatus(null);
|
||||
}
|
||||
}
|
||||
|
||||
// handles when user uses mouse to "swipe", or
|
||||
// more specifically drag the card to one side or the other
|
||||
const handleSwipe = () => {
|
||||
onSwipe(idRef.current, statusRef.current);
|
||||
setStatus(null);
|
||||
};
|
||||
|
||||
// these handlers are explicit and used for when the
|
||||
// user clicks on buttons
|
||||
const handleLike = () => {
|
||||
onSwipe(idRef.current, true);
|
||||
setStatus(null);
|
||||
};
|
||||
const handleNope = () => {
|
||||
onSwipe(idRef.current, false);
|
||||
setStatus(null);
|
||||
};
|
||||
|
||||
const isLiked = status === true;
|
||||
const notLiked = status === false;
|
||||
|
||||
const likeClass = `${c.status} ${isLiked ? c.statusVisible : c.statusNull} ${c.like}`;
|
||||
const nopeClass = `${c.status} ${notLiked ? c.statusVisible : c.statusNull} ${c.nope}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Draggable id="active-profile" onDrag={onDrag} onDrop={handleSwipe}>
|
||||
<Card raised className={c.root}>
|
||||
<StatusDisplay className={likeClass} text={t('APPS_MATCH_LIKED')} visible={isLiked} />
|
||||
<StatusDisplay className={nopeClass} text={t('APPS_MATCH_NOPE')} visible={notLiked} />
|
||||
<Profile profile={profile} />
|
||||
</Card>
|
||||
</Draggable>
|
||||
<Box className={c.buttons} display="flex" justifyContent="center">
|
||||
<Tooltip title={t('APPS_MATCH_DISLIKE')} aria-label="dislike">
|
||||
<Fab
|
||||
size="large"
|
||||
color="secondary"
|
||||
aria-label="dislike"
|
||||
onClick={handleNope}
|
||||
className={c.button}
|
||||
>
|
||||
<CancelIcon />
|
||||
</Fab>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('APPS_MATCH_LIKE')} aria-label="like">
|
||||
<Fab
|
||||
size="large"
|
||||
color="primary"
|
||||
aria-label="like"
|
||||
onClick={handleLike}
|
||||
className={c.button}
|
||||
>
|
||||
<FireIcon />
|
||||
</Fab>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ActiveProfile;
|
||||
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
||||
import HomeIcon from '@material-ui/icons/Whatshot';
|
||||
import GroupIcon from '@material-ui/icons/Group';
|
||||
import ProfileIcon from '@material-ui/icons/Person';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
width: '100%',
|
||||
},
|
||||
});
|
||||
|
||||
export function MatchBottomNavigation({ activePage, handleChange }) {
|
||||
const classes = useStyles();
|
||||
|
||||
console.log(activePage);
|
||||
|
||||
return (
|
||||
<BottomNavigation value={activePage} onChange={handleChange} className={classes.root}>
|
||||
<BottomNavigationAction component={Link} to="/match" icon={<HomeIcon />} />
|
||||
<BottomNavigationAction component={Link} to="/match/matches" icon={<GroupIcon />} />
|
||||
<BottomNavigationAction component={Link} to="/match/profile" icon={<ProfileIcon />} />
|
||||
</BottomNavigation>
|
||||
);
|
||||
}
|
||||
|
||||
export default MatchBottomNavigation;
|
||||
@@ -0,0 +1,61 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { makeStyles } from '@material-ui/core';
|
||||
|
||||
import { LikeorDislikeDraggableElement } from '../utils/drag';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
position: 'relative',
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
},
|
||||
like: {
|
||||
position: 'absolute',
|
||||
zIndex: 20,
|
||||
padding: '5px 15px',
|
||||
top: 100,
|
||||
|
||||
color: 'green',
|
||||
border: '4px solid green',
|
||||
right: 15,
|
||||
},
|
||||
nope: {
|
||||
position: 'absolute',
|
||||
zIndex: 20,
|
||||
padding: '5px 15px',
|
||||
top: 100,
|
||||
|
||||
color: 'red',
|
||||
border: '4px solid red',
|
||||
left: 15,
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
id: string;
|
||||
children: JSX.Element | JSX.Element[];
|
||||
onDrag: (deltaX: number) => void;
|
||||
onDrop: () => void;
|
||||
}
|
||||
|
||||
const MAX_ROTATION_DEG = 15;
|
||||
|
||||
function Draggable({ id, children, onDrag, onDrop }: IProps) {
|
||||
const classes = useStyles();
|
||||
const elementRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const drag = new LikeorDislikeDraggableElement(elementRef, MAX_ROTATION_DEG, onDrag, onDrop);
|
||||
return () => drag.cleanup();
|
||||
}, [elementRef]); // eslint-disable-line
|
||||
|
||||
return (
|
||||
<>
|
||||
<div ref={elementRef} key={id} id={id} className={classes.root}>
|
||||
{children}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Draggable;
|
||||
@@ -0,0 +1,28 @@
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, Typography } from '@material-ui/core';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
root: {
|
||||
color: theme.palette.primary.main,
|
||||
fontSize: theme.typography.fontSize,
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
paddingTop: '140px',
|
||||
},
|
||||
}));
|
||||
|
||||
function NoProfiles() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<Typography variant="h5">{t('APPS_MATCH_NO_PROFILES')}</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default NoProfiles;
|
||||
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import { Box, CircularProgress } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
progress: {
|
||||
marginTop: '140px',
|
||||
},
|
||||
});
|
||||
|
||||
function Loader() {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<CircularProgress size={60} className={classes.progress} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default Loader;
|
||||
@@ -0,0 +1,158 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Route } from 'react-router-dom';
|
||||
|
||||
import { AppWrapper } from '../../../ui/components';
|
||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { MatchThemeProvider } from '../providers/MatchThemeProvider';
|
||||
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import MatchBottomNavigation from '../components/BottomNavigation';
|
||||
import MatchPage from './views/MatchPage';
|
||||
import ProfileEditor from './views/ProfileEditor';
|
||||
import MatchList from './views/MatchList';
|
||||
import { MatchEvents } from '../../../../../typings/match';
|
||||
import { useProfile } from '../hooks/useProfile';
|
||||
|
||||
export const MatchApp = () => {
|
||||
const match = useApp('MATCH');
|
||||
const [activePage, setActivePage] = useState(0);
|
||||
const { noProfileExists } = useProfile();
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send(MatchEvents.INITIALIZE);
|
||||
}, []);
|
||||
|
||||
const handlePageChange = (e, page) => setActivePage(page);
|
||||
|
||||
return (
|
||||
<MatchThemeProvider>
|
||||
<AppWrapper id="contact-app">
|
||||
<AppTitle app={match} />
|
||||
{noProfileExists ? (
|
||||
<AppContent>
|
||||
<ProfileEditor />
|
||||
</AppContent>
|
||||
) : (
|
||||
<>
|
||||
<AppContent>
|
||||
<Route path="/match/" exact component={MatchPage} />
|
||||
<Route path="/match/matches" exact component={MatchList} />
|
||||
<Route path="/match/profile" exact component={ProfileEditor} />
|
||||
</AppContent>
|
||||
<MatchBottomNavigation activePage={activePage} handleChange={handlePageChange} />
|
||||
</>
|
||||
)}
|
||||
</AppWrapper>
|
||||
</MatchThemeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
InjectDebugData(
|
||||
[
|
||||
{
|
||||
app: 'MATCH',
|
||||
method: 'phone:getMatchProfilesSuccess',
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
image:
|
||||
'https://cdn.vox-cdn.com/thumbor/9xCALlkm2Mc0HQk8kMr1Ui3YNbc=/0x0:5464x3070/920x613/filters:focal(2295x1098:3169x1972):format(webp)/cdn.vox-cdn.com/uploads/chorus_image/image/67031748/shutterstock_1450403549.0.jpg',
|
||||
name: 'Person Alpha',
|
||||
bio:
|
||||
'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.',
|
||||
createdAt: 1615932985,
|
||||
updatedAt: 1615932985,
|
||||
lastActive: 1616004986,
|
||||
job: 'Gardener',
|
||||
location: 'Grapeseed',
|
||||
tags: 'gardening',
|
||||
phoneNumber: '987-6543',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
image:
|
||||
'https://media.cntraveler.com/photos/5f8f09c3a078e9112956774d/16:9/w_1600%2Cc_limit/Chicago-GettyImages-1065188752.jpg',
|
||||
name: 'Person Beta',
|
||||
bio: 'l impedit quo minus id quod maxime placeat facere possimus',
|
||||
createdAt: 1615846585,
|
||||
updatedAt: 1615846585,
|
||||
lastActive: 1615850185,
|
||||
job: 'Mechanic',
|
||||
location: 'Harmony',
|
||||
tags: 'tinkering,robotics',
|
||||
phoneNumber: '654-3219',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
image: 'https://www.langan.com/wp-content/uploads/2019/02/Boston-996x554.jpg',
|
||||
name: 'Person Charlie',
|
||||
bio: 'ut aut reiciendis voluptatibus',
|
||||
createdAt: 1615850185,
|
||||
updatedAt: 1615850185,
|
||||
lastActive: 1613607385,
|
||||
job: 'Lawyer',
|
||||
location: 'Los Santos',
|
||||
tags: 'reading,coolstuff, coffee',
|
||||
phoneNumber: '123-4567',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
app: 'MATCH',
|
||||
method: 'phone:getMyProfileSuccess',
|
||||
data: {
|
||||
id: 4,
|
||||
image:
|
||||
'https://www.middlebury.edu/institute/sites/www.middlebury.edu.institute/files/styles/1040x585/public/2018-10/Nashville-skyline.jpg?fv=mS11EKrT&itok=HNhHqYUX',
|
||||
name: 'Kire Says',
|
||||
bio: "Kire's cool profile that has many cool things. And others.",
|
||||
createdAt: 1615932985,
|
||||
updatedAt: 1615932985,
|
||||
lastActive: 1616004986,
|
||||
job: 'Engineer',
|
||||
location: 'Boston',
|
||||
tags: 'code,books',
|
||||
phoneNumber: '999-9999',
|
||||
},
|
||||
},
|
||||
{
|
||||
app: 'MATCH',
|
||||
method: 'phone:getMatchesSuccess',
|
||||
data: [
|
||||
{
|
||||
id: 5,
|
||||
image:
|
||||
'https://media.cntraveler.com/photos/5f8f09c3a078e9112956774d/16:9/w_1600%2Cc_limit/Chicago-GettyImages-1065188752.jpg',
|
||||
name: 'Person Delta',
|
||||
bio: 'l impedit quo minus id quod maxime placeat facere possimus',
|
||||
createdAt: 1615846585,
|
||||
updatedAt: 1615846585,
|
||||
lastActive: 1615850185,
|
||||
matchedAt: 1613607385,
|
||||
job: 'Mechanic',
|
||||
location: 'Harmony',
|
||||
tags: 'tinkering,robotics',
|
||||
phoneNumber: '654-3219',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
image: 'https://www.langan.com/wp-content/uploads/2019/02/Boston-996x554.jpg',
|
||||
name: 'Person Echo',
|
||||
bio: 'ut aut reiciendis voluptatibus',
|
||||
createdAt: 1615850185,
|
||||
updatedAt: 1615850185,
|
||||
lastActive: 1613607385,
|
||||
job: 'Lawyer',
|
||||
location: 'Los Santos',
|
||||
tags: 'reading,coolstuff, coffee',
|
||||
phoneNumber: '123-4567',
|
||||
matchedAt: 1613607385,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
200,
|
||||
);
|
||||
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import { Box, Typography } from '@material-ui/core';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
root: {
|
||||
color: theme.palette.primary.main,
|
||||
fontSize: theme.typography.fontSize,
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
textAlign: 'center',
|
||||
padding: '140px 15px 15px 15px',
|
||||
},
|
||||
}));
|
||||
|
||||
interface IProps {
|
||||
text: string;
|
||||
}
|
||||
|
||||
function PageText({ text }: IProps) {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<Typography variant="h5">{text}</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default PageText;
|
||||
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import { Box } from '@material-ui/core';
|
||||
|
||||
function StatusDisplay({ className, visible, text }) {
|
||||
const style = { opacity: visible ? '0.65' : '0.0' };
|
||||
|
||||
return (
|
||||
<Box className={className} style={style}>
|
||||
{text}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default StatusDisplay;
|
||||
@@ -0,0 +1,62 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import ListItemText from '@material-ui/core/ListItemText';
|
||||
import { Box, Button, ListItem, makeStyles } from '@material-ui/core';
|
||||
import PersonIcon from '@material-ui/icons/Person';
|
||||
import ChatIcon from '@material-ui/icons/Chat';
|
||||
|
||||
import { FormattedMatch } from '../../../../../../typings/match';
|
||||
import Profile from '../profile/Profile';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
profile: {
|
||||
position: 'relative',
|
||||
height: '90%',
|
||||
marginTop: '15px',
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
match: FormattedMatch;
|
||||
}
|
||||
|
||||
export const Match = ({ match }: IProps) => {
|
||||
const history = useHistory();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [showProfile, setShowProfile] = useState(false);
|
||||
|
||||
const handleMessage = () => {
|
||||
history.push(`/messages/new/${match.phoneNumber}`);
|
||||
};
|
||||
|
||||
const handleProfile = () => {
|
||||
setShowProfile((show) => !show);
|
||||
};
|
||||
|
||||
const secondaryText = t('APPS_MATCH_PROFILE_MATCHED_AT', {
|
||||
matchedAt: match.matchedAtFormatted,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<ListItem divider>
|
||||
<ListItemText primary={match.name} secondary={secondaryText} />
|
||||
<Button onClick={handleProfile}>
|
||||
<PersonIcon />
|
||||
</Button>
|
||||
<Button onClick={handleMessage}>
|
||||
<ChatIcon />
|
||||
</Button>
|
||||
</ListItem>
|
||||
{showProfile && (
|
||||
<Box className={classes.profile}>
|
||||
<Profile profile={match} />
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Match;
|
||||
@@ -0,0 +1,78 @@
|
||||
import React from 'react';
|
||||
import { CardContent, CardMedia, Chip, Typography } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { FormattedProfile, FormattedMatch } from '../../../../../../typings/match';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {},
|
||||
tags: {
|
||||
position: 'absolute',
|
||||
bottom: '40%',
|
||||
},
|
||||
tag: {
|
||||
margin: '3px 3px 0px 0px',
|
||||
opacity: '0.8',
|
||||
},
|
||||
media: {
|
||||
height: '60%',
|
||||
},
|
||||
content: {
|
||||
height: '40%',
|
||||
overflowY: 'auto',
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
profile: FormattedProfile | FormattedMatch;
|
||||
}
|
||||
|
||||
const DEFAULT_IMAGE = 'https://upload.wikimedia.org/wikipedia/commons/a/ac/No_image_available.svg';
|
||||
|
||||
const Profile = ({ profile }: IProps) => {
|
||||
const c = useStyles();
|
||||
const { t } = useTranslation();
|
||||
|
||||
function parseSecondaryBio(): string | undefined {
|
||||
const { location, job } = profile;
|
||||
if (location && job) {
|
||||
return `${location} - ${job}`;
|
||||
} else if (location) {
|
||||
return location;
|
||||
} else if (job) {
|
||||
return job;
|
||||
}
|
||||
}
|
||||
|
||||
const bioSecondary = parseSecondaryBio();
|
||||
|
||||
return (
|
||||
<>
|
||||
<CardContent className={c.tags}>
|
||||
{profile.tagList.map((tag) => (
|
||||
<Chip className={c.tag} label={tag} color="primary" />
|
||||
))}
|
||||
</CardContent>
|
||||
<CardMedia className={c.media} image={profile.image || DEFAULT_IMAGE} title={profile.name} />
|
||||
<CardContent className={c.content}>
|
||||
<Typography gutterBottom variant="h4" component="h2">
|
||||
{profile.name}
|
||||
</Typography>
|
||||
<Typography gutterBottom color="textSecondary" component="p">
|
||||
{t('APPS_MATCH_PROFILE_LAST_ACTIVE', { lastActive: profile.lastActiveFormatted })}
|
||||
</Typography>
|
||||
{bioSecondary && (
|
||||
<Typography gutterBottom variant="body1" color="textSecondary" component="p">
|
||||
{bioSecondary}
|
||||
</Typography>
|
||||
)}
|
||||
<Typography variant="body2" color="textSecondary" component="p">
|
||||
{profile.bio}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Profile;
|
||||
@@ -0,0 +1,128 @@
|
||||
import React, { useState } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import {
|
||||
Profile as IProfile,
|
||||
FormattedProfile,
|
||||
MatchEvents,
|
||||
} from '../../../../../../typings/match';
|
||||
import ProfileField from '../../../../ui/components/ProfileField';
|
||||
import UpdateButton from '../../../../ui/components/UpdateButton';
|
||||
import { Card } from '@material-ui/core';
|
||||
import Profile from './Profile';
|
||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||
import PageText from '../PageText';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
position: 'relative',
|
||||
width: '100%',
|
||||
height: 'calc(100% - 40px)',
|
||||
padding: '15px',
|
||||
},
|
||||
card: {
|
||||
position: 'absolute',
|
||||
margin: '15px 15px 25px 15px',
|
||||
height: 'calc(100% - 80px)',
|
||||
width: 'calc(100% - 30px)',
|
||||
overflow: 'hidden',
|
||||
},
|
||||
spacer: {
|
||||
height: '8px',
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
profile: FormattedProfile;
|
||||
showPreview: boolean;
|
||||
}
|
||||
|
||||
export function ProfileForm({ profile, showPreview }: IProps) {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { config } = usePhone();
|
||||
|
||||
// note that this assumes we are defensively checking
|
||||
// that profile is not null in a parent above this component.
|
||||
// Annoyingling adding conditionals above this line to not render
|
||||
// when profile === null results in a react error that different
|
||||
// amounts of hooks are rendering
|
||||
const [image, setImage] = useState(profile?.image || '');
|
||||
const [name, setName] = useState(profile?.name || '');
|
||||
const [bio, setBio] = useState(profile?.bio || '');
|
||||
const [job, setJob] = useState(profile?.job || '');
|
||||
const [location, setLocation] = useState(profile?.location || '');
|
||||
const [tags, setTags] = useState(profile?.tags || '');
|
||||
|
||||
const update: FormattedProfile = {
|
||||
...profile,
|
||||
image,
|
||||
name,
|
||||
bio,
|
||||
location,
|
||||
job,
|
||||
tagList: tags.split(',').map((tag) => tag.trim()),
|
||||
};
|
||||
|
||||
const handleUpdate = () => {
|
||||
const updatedProfile: IProfile = {
|
||||
...update,
|
||||
name: update.name.trim(),
|
||||
image: update.image.trim(),
|
||||
tags: update.tagList.join(','),
|
||||
};
|
||||
const event = profile ? MatchEvents.UPDATE_MY_PROFILE : MatchEvents.CREATE_MY_PROFILE;
|
||||
Nui.send(event, updatedProfile);
|
||||
};
|
||||
|
||||
if (!profile && !config.match.allowEdtiableProfileName) {
|
||||
return <PageText text={t('APPS_MATCH_PROFILE_CONFIGURATION')} />;
|
||||
}
|
||||
|
||||
if (showPreview) {
|
||||
return (
|
||||
<Card raised className={classes.card}>
|
||||
<Profile profile={update} />
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_IMAGE')}
|
||||
value={update.image}
|
||||
handleChange={setImage}
|
||||
allowChange
|
||||
/>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_NAME')}
|
||||
value={name}
|
||||
handleChange={setName}
|
||||
allowChange={config.match.allowEdtiableProfileName}
|
||||
/>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_BIO')}
|
||||
value={update.bio}
|
||||
handleChange={setBio}
|
||||
multiline
|
||||
/>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_LOCATION')}
|
||||
value={update.location}
|
||||
handleChange={setLocation}
|
||||
/>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_JOB')}
|
||||
value={update.job}
|
||||
handleChange={setJob}
|
||||
/>
|
||||
<ProfileField label={t('APPS_MATCH_EDIT_PROFILE_TAGS')} value={tags} handleChange={setTags} />
|
||||
<UpdateButton handleClick={handleUpdate} loading={false} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProfileForm;
|
||||
@@ -0,0 +1,52 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, makeStyles } from '@material-ui/core';
|
||||
|
||||
import { useMatches } from '../../hooks/useMatches';
|
||||
import Loader from '../Loader';
|
||||
import PageText from '../PageText';
|
||||
import Match from '../matches/Match';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { MatchEvents } from '../../../../../../typings/match';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: '100%',
|
||||
},
|
||||
});
|
||||
|
||||
const MINIMUM_LOAD_TIME = 1500;
|
||||
|
||||
function MatchList() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { matches, error } = useMatches();
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
||||
// We make the conscious descion here to fetch matches everytime
|
||||
// a user loads this page because this list is dependent on
|
||||
// other player's database interactions (i.e. their likes/dislikes)
|
||||
// not just the current players.
|
||||
// This is less performant but means that we will always have the
|
||||
// correct state when the player views this page
|
||||
useEffect(() => {
|
||||
Nui.send(MatchEvents.GET_MATCHES);
|
||||
window.setTimeout(() => {
|
||||
setLoaded(true);
|
||||
}, MINIMUM_LOAD_TIME);
|
||||
}, []);
|
||||
|
||||
if (error) return <PageText text={t('APPS_MATCH_MATCHES_ERROR')} />;
|
||||
if (!loaded || !matches) return <Loader />;
|
||||
if (matches.length === 0) return <PageText text={t('APPS_MATCH_NO_MATCHES')} />;
|
||||
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
{matches.map((match) => (
|
||||
<Match key={match.id} match={match} />
|
||||
))}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default MatchList;
|
||||
@@ -0,0 +1,53 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Paper } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useProfiles } from '../../hooks/useProfiles';
|
||||
import Loader from '../Loader';
|
||||
import PageText from '../PageText';
|
||||
import ActiveProfile from '../ActiveProfile';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
overflow: 'hidden',
|
||||
},
|
||||
});
|
||||
|
||||
// set a minimum load time so the user doesn't see a flash
|
||||
// of the loader and then the matches themselves
|
||||
const MINIMUM_LOAD_TIME = 1250;
|
||||
|
||||
const MatchPage = () => {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { profiles, error, activeProfile, setViewed } = useProfiles();
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
window.setTimeout(() => {
|
||||
setLoaded(true);
|
||||
}, MINIMUM_LOAD_TIME);
|
||||
}, []);
|
||||
|
||||
const handleSwipe = (id: number, liked: boolean) => {
|
||||
// the user didn't choose (didn't swipe far enough)
|
||||
if (liked === null) return;
|
||||
|
||||
setViewed(id, liked);
|
||||
};
|
||||
|
||||
if (error) return <PageText text={t('APPS_MATCH_PROFILES_ERROR')} />;
|
||||
if (!loaded || !profiles) return <Loader />;
|
||||
if (!activeProfile) return <PageText text={t('APPS_MATCH_NO_PROFILES')} />;
|
||||
|
||||
return (
|
||||
<Paper className={classes.root} square>
|
||||
<ActiveProfile profile={activeProfile} onSwipe={handleSwipe} />
|
||||
</Paper>
|
||||
);
|
||||
};
|
||||
|
||||
export default MatchPage;
|
||||
@@ -0,0 +1,45 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { Box, FormControlLabel, Switch } from '@material-ui/core';
|
||||
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
import Loader from '../Loader';
|
||||
import ProfileForm from '../profile/ProfileForm';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
},
|
||||
switch: {
|
||||
marginLeft: '15px',
|
||||
},
|
||||
});
|
||||
|
||||
function ProfileEditor() {
|
||||
const { profile, noProfileExists } = useProfile();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [showPreview, setShowPreview] = useState(false);
|
||||
|
||||
const toggleSwitch = () => {
|
||||
setShowPreview((preview) => !preview);
|
||||
};
|
||||
|
||||
if (!profile && !noProfileExists) return <Loader />;
|
||||
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<Box className={classes.switch}>
|
||||
<FormControlLabel
|
||||
control={<Switch checked={showPreview} onChange={toggleSwitch} />}
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_PREVIEW')}
|
||||
/>
|
||||
</Box>
|
||||
<ProfileForm showPreview={showPreview} profile={profile} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProfileEditor;
|
||||
Reference in new issue
Block a user