-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from JimTheCat/CU-8696pcxy1_Create-Search-page…
…_Patryk-Kosiski Cu 8696pcxy1 create search page patryk kosiski
- Loading branch information
Showing
8 changed files
with
162 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {Avatar, Button, Card, Divider, Group, Stack, Text} from "@mantine/core"; | ||
|
||
type SuggestedUser = { | ||
id: number; | ||
name: string; | ||
avatar: string; | ||
tag: string; | ||
}; | ||
|
||
const suggestedUsers: SuggestedUser[] = [ | ||
{id: 1, name: "Alice Johnson", avatar: "https://via.placeholder.com/40", tag: "@alicejohnson"}, | ||
{id: 2, name: "Bob Smith", avatar: "https://via.placeholder.com/40", tag: "@bobsmith"}, | ||
{id: 3, name: "Charlie Brown", avatar: "https://via.placeholder.com/40", tag: "@charliebrown"}, | ||
]; | ||
|
||
export const SuggestedUsers = () => { | ||
return ( | ||
<Card p="lg" withBorder mt="lg"> | ||
<Text size="lg" mb="sm"> | ||
Suggested Users | ||
</Text> | ||
<Divider mb={"md"}/> | ||
<Group> | ||
{suggestedUsers.map((user) => ( | ||
<Group key={user.id} justify="flex-start"> | ||
<Group> | ||
<Avatar src={user.avatar} size={"lg"} radius={180}/> | ||
<Stack gap={0}> | ||
<Text>{user.name}</Text> | ||
<Text>{user.tag}</Text> | ||
</Stack> | ||
</Group> | ||
<Button variant="light" size="xs"> | ||
Follow | ||
</Button> | ||
</Group> | ||
))} | ||
</Group> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './SuggestedUsers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import {Autocomplete, AutocompleteProps, Avatar, Box, ComboboxItem, Group, OptionsFilter, Text} from '@mantine/core'; | ||
import {useState} from 'react'; | ||
import {IconSearch, IconX} from "@tabler/icons-react"; | ||
import {SuggestedUsers} from "../../Components/SuggestedUsers"; | ||
import {useNavigate} from "react-router-dom"; | ||
|
||
type SuggestedUser = { | ||
id: number; | ||
name: string; | ||
avatar: string; | ||
tag: string; | ||
}; | ||
|
||
// Mockowe dane użytkowników | ||
const users: SuggestedUser[] = [ | ||
{id: 1, name: 'Emily Johnson', avatar: 'https://via.placeholder.com/40', tag: '@emily'}, | ||
{id: 2, name: 'Ava Rodriguez', avatar: 'https://via.placeholder.com/40', tag: '@ava'}, | ||
{id: 3, name: 'Olivia Chen', avatar: 'https://via.placeholder.com/40', tag: '@olivia'}, | ||
{id: 4, name: 'Ethan Barnes', avatar: 'https://via.placeholder.com/40', tag: '@ethan'}, | ||
{id: 5, name: 'Mason Taylor', avatar: 'https://via.placeholder.com/40', tag: '@mason'}, | ||
{id: 6, name: "Jan Kowalski", avatar: 'https://via.placeholder.com/40', tag: '@johndoe'}, | ||
]; | ||
|
||
const usersData = users.reduce((acc, user) => { | ||
acc[user.name] = {avatar: user.avatar, tag: user.tag}; | ||
return acc; | ||
}, {} as Record<string, { avatar: string; tag: string }>); | ||
|
||
const renderAutocompleteOption: AutocompleteProps['renderOption'] = ({option}) => ( | ||
<Group gap="sm"> | ||
<Avatar src={usersData[option.value].avatar} size={36} radius="xl"/> | ||
<div> | ||
<Text size="sm">{option.value}</Text> | ||
<Text size="xs" opacity={0.5}> | ||
{usersData[option.value].tag} | ||
</Text> | ||
</div> | ||
</Group> | ||
); | ||
|
||
export const Search = () => { | ||
const [query, setQuery] = useState(''); | ||
const navigate = useNavigate(); | ||
|
||
const convertedData = users | ||
.map((user) => ({ | ||
value: user.name, | ||
label: user.name, | ||
tag: user.tag, | ||
avatar: user.avatar, | ||
})); | ||
|
||
// Dane do Autocomplete (nazwy użytkowników i tagi użytkowników) | ||
const optionsFilter: OptionsFilter = ({options, search}) => { | ||
|
||
if (!search) { | ||
return options; | ||
} | ||
|
||
return (options as ComboboxItem[]).filter((option) => { | ||
const searchLower = search.toLowerCase(); | ||
return option.value.toLowerCase().includes(searchLower) || usersData[option.value].tag.toLowerCase().includes(searchLower); | ||
}); | ||
}; | ||
|
||
const handleClear = () => { | ||
setQuery(''); | ||
} | ||
|
||
return ( | ||
<Box p="xl" w="60dvw"> | ||
<Autocomplete | ||
data={convertedData} | ||
leftSection={<IconSearch/>} | ||
rightSection={query ? <IconX onClick={handleClear} style={{cursor: "pointer"}}/> : null} | ||
renderOption={renderAutocompleteOption} | ||
maxDropdownHeight={300} | ||
placeholder="Wyszukaj" | ||
filter={optionsFilter} | ||
limit={5} | ||
size="xl" | ||
radius="xl" | ||
value={query} | ||
onChange={setQuery} | ||
onOptionSubmit={(value) => { | ||
navigate(`/profile/${usersData[value].tag}`) | ||
}} | ||
/> | ||
|
||
<SuggestedUsers/> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Search'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters