forked from RoBorregos/RoboLinks
-
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.
- Loading branch information
1 parent
367b68b
commit 8e97c0d
Showing
17 changed files
with
355 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- [ ] hacer q la search bar renderice los resultados o que se refetchee bien la pagina | ||
- [ ] |
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
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,27 @@ | ||
import { Spinner, Stack } from "@chakra-ui/react"; | ||
import React from "react"; | ||
import { LinkComponent } from "./LinkComponent"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import client from "../../client"; | ||
|
||
const LinkStack = ({ search, tags }) => { | ||
const { data, isLoading, isError, isFetching } = useQuery(["links"], () => | ||
client.post("/Link/searchLinks", { | ||
search: search, | ||
tags: tags, | ||
}) | ||
); | ||
console.log("LinkStack", isFetching); | ||
console.log(data); | ||
return ( | ||
<Stack m="2%" spacing={8}> | ||
{isLoading ? ( | ||
<Spinner /> | ||
) : ( | ||
data.data?.map((link) => <LinkComponent idLink={link.idLink} />) | ||
)} | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default LinkStack; |
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,115 @@ | ||
import { | ||
Input, | ||
Box, | ||
HStack, | ||
Button, | ||
Menu, | ||
MenuButton, | ||
MenuItem, | ||
MenuList, | ||
Badge, | ||
Code, | ||
Spacer, | ||
Center, | ||
Text, | ||
IconButton, | ||
} from "@chakra-ui/react"; | ||
import { SearchMode, SearchModeEnum } from "../../types/SearchMode"; | ||
import { useState } from "react"; | ||
import { useQuery, useQueryClient } from "@tanstack/react-query"; | ||
import client from "../../client"; | ||
import { AddIcon, CheckIcon, CloseIcon } from "@chakra-ui/icons"; | ||
|
||
const SearchBar = ({ setSearch, setTags, search }) => { | ||
const queryClient = useQueryClient(); | ||
const [selectedTags, setSelectedTags] = useState(new Set() as Set<number>); | ||
const [isSelected, setIsSelected] = useState({}); | ||
const { data, isLoading, error } = useQuery(["tags"], () => | ||
client.get("/Tag/getTags") | ||
); | ||
const handleSearch = () => { | ||
queryClient.fetchQuery(["links"], () => | ||
client.post("/Link/searchLinks", { | ||
search: search, | ||
tags: Array.from(selectedTags), | ||
}) | ||
); | ||
}; | ||
return ( | ||
<> | ||
<Box> | ||
<HStack> | ||
<IconButton | ||
aria-label="Add new Link" | ||
icon={<AddIcon />} | ||
onClick={() => {}} | ||
/> | ||
<Input | ||
focusBorderColor="blue.500" | ||
placeholder="Search" | ||
onChange={(e) => { | ||
setSearch(e.target.value); | ||
handleSearch(); | ||
}} | ||
/> | ||
<Button onClick={handleSearch}>Search</Button> | ||
<Menu> | ||
<MenuButton> | ||
<Button> | ||
<Badge colorScheme={"green"}>Tags</Badge> | ||
</Button> | ||
</MenuButton> | ||
<MenuList> | ||
{data?.data?.map((tag) => { | ||
return ( | ||
<MenuItem | ||
key={tag.idTag} | ||
onClick={() => { | ||
setIsSelected({ ...isSelected, [tag.idTag]: true }); | ||
selectedTags.add(tag.idTag); | ||
setSelectedTags(selectedTags); | ||
setTags(Array.from(selectedTags)); | ||
}} | ||
> | ||
<HStack justify={"space-between"}> | ||
<Badge colorScheme={tag.tagColor}>{tag.tagName}</Badge> | ||
<Spacer /> | ||
{isSelected[tag.idTag] ? <CheckIcon /> : null} | ||
</HStack> | ||
</MenuItem> | ||
); | ||
})} | ||
</MenuList> | ||
</Menu> | ||
<HStack> | ||
{Array.from(selectedTags).map((tag) => { | ||
const tagData = data?.data?.find((t) => t.idTag === tag); | ||
return ( | ||
<Badge | ||
key={tagData.idTag} | ||
colorScheme={tagData.tagColor} | ||
onClick={() => { | ||
setIsSelected({ ...isSelected, [tagData.idTag]: false }); | ||
selectedTags.delete(tagData.idTag); | ||
setSelectedTags(selectedTags); | ||
setTags(Array.from(selectedTags)); | ||
}} | ||
cursor={"pointer"} | ||
> | ||
<HStack> | ||
<Text>{tagData.tagName}</Text> | ||
<Center> | ||
<CloseIcon /> | ||
</Center> | ||
</HStack> | ||
</Badge> | ||
); | ||
})} | ||
</HStack> | ||
</HStack> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
export default SearchBar; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.