From 01b571735cb371942d4ee997f94c5ccb98265c39 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 9 Mar 2021 17:27:23 +0100 Subject: cool search function working :tada: --- api/social/search.py | 2 +- pages/search.tsx | 104 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 80 insertions(+), 26 deletions(-) diff --git a/api/social/search.py b/api/social/search.py index 712d0b8..a9bb385 100644 --- a/api/social/search.py +++ b/api/social/search.py @@ -5,7 +5,7 @@ import json search = Blueprint('search', __name__) -@search.route('/search', methods = ['GET', 'POST']) +@search.route('/search', methods = ['POST']) def index(): data_string = request.data or "{}" data = json.loads(data_string) diff --git a/pages/search.tsx b/pages/search.tsx index 8aef64b..52dfed5 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -1,38 +1,92 @@ -import { Component } from 'react'; +import { FormEvent, useState } from 'react'; +import axios from 'axios'; import { NavBar } from '../components/navbar'; import { Vierkant, Button, Input } from '../components/ui'; import { CenteredPage, PageTitle } from '../components/page'; +import { AccountAvatar } from '../components/account'; +import { userInfo } from '../api/api'; import SearchOutlinedIcon from '@material-ui/icons/SearchOutlined'; -function SearchBar() { - return - - - +function search(callback: (results: Array) => void) { + var query: string = (document.getElementById("searchBar") as HTMLInputElement).value; + if (query.length < 3) return; + + axios.request<{ "results": Array }>({ + method: "post", + url: `${window.location.origin}/api/social/search`, + headers: {"content-type": "application/json"}, + data: { "query": query } + }) + .then(response => callback(response.data.results)) + .catch(() => {}); } -export default class HomePage extends Component { - render () { - return
- - - Zoeken - - +function SearchResults(props: { userList: Array }) { + return
+ { props.userList?.map(user => ) } +
; +} + +function SearchResult(props: { user: userInfo }) { + return +
+ +
+ {props.user.username} +

{props.user.status || "Hey daar!, ik ben nieuw op deze website en heb nog geen status."}

+
+
; +} + +function SearchBar(props: { + searchFunction: (event?: FormEvent) => void; +}) { + return +
+ + + +
+
+} + +export default function HomePage() { + var [results, setResults] = useState>([]); + var getSearchResults = (event?: FormEvent) => { + event.preventDefault(); + search(results => setResults(results)); } + + return
+ + + Zoeken + + + +
} -- cgit v1.2.3