From da2fba59ddaee800eceee984198da0228fcb5b80 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 21 Apr 2021 16:08:35 +0200 Subject: added search in new game dialog (not finished) --- pages/game.tsx | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'pages') diff --git a/pages/game.tsx b/pages/game.tsx index de2c089..f6c6f5b 100644 --- a/pages/game.tsx +++ b/pages/game.tsx @@ -1,11 +1,13 @@ import Icon from '@mdi/react'; import axios from 'axios'; import copy from 'copy-to-clipboard'; +import Fuse from 'fuse.js'; import { useContext, useEffect, useState } from 'react'; import * as cookies from 'react-cookies'; import { Socket } from 'socket.io-client'; import { SocketContext } from '../components/socketContext'; +import { userInfo } from '../api/api'; import { DialogBox } from '../components/dialogBox'; import { GameBar } from '../components/gameBar'; import { CurrentGameSettings } from '../components/gameSettings'; @@ -15,11 +17,13 @@ import { ToastContext, toastType } from '../components/toast'; import { Button, IconLabelButton, SearchBar } from '../components/ui'; import { VoerBord } from '../components/voerBord'; +import AddIcon from '@material-ui/icons/Add'; import FlagOutlinedIcon from '@material-ui/icons/FlagOutlined'; import LinkRoundedIcon from '@material-ui/icons/LinkRounded'; import RefreshIcon from '@material-ui/icons/Refresh'; import WifiTetheringRoundedIcon from '@material-ui/icons/WifiTetheringRounded'; import { mdiContentCopy } from '@mdi/js'; +import { AccountAvatar } from '../components/account'; function VoerGame(props: { gameID: string; @@ -139,11 +143,28 @@ function GameOutcomeDialog(props: { ; } +function InviteableFriend(props: { user?: userInfo; }) { + return
+ + {props.user?.username} +
; +} + export default function GamePage() { var [gameID, setGameID] = useState(''); var [player1, setPlayer1] = useState(true); var [active, setActive] = useState(false); var [gameIDUrl, setGameIDUrl] = useState(''); + var [friendList, setFriendList] = useState([]); + + var [query, setQuery] = useState(''); + var [visibleFriends, setVisibleFriends] = useState([]); + + var fuse = new Fuse(friendList, { + keys: ['username'], + isCaseSensitive: false, + }); var { io } = useContext(SocketContext); var { toast } = useContext(ToastContext); @@ -173,6 +194,27 @@ export default function GamePage() { setGameID(gameIDUrl); }, []); + useEffect(() => { + axios.request<{ friends: Array; }>({ + method: 'get', + url: '/api/social/list/friends', + }) + .then(response => { + console.log(response.data.friends); + setFriendList(response.data.friends); + }) + .catch(err => { + toast({ message: 'error', type: 'error', description: err.toString() }); + }); + }, []); + + useEffect(() => { + var fuseSearch = fuse.search(query); + var results = fuseSearch.map(res => res.item).slice(0, 5); + + setVisibleFriends(results); + }, [query]); + useEffect(() => { io.on('gameStart', () => setActive(true)); }, []); @@ -246,7 +288,10 @@ export default function GamePage() {

Uitnodigen via link

- +
+ setQuery(q)} /> + {visibleFriends.map(user => )} +
; -- cgit v1.2.3