Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results Bar Scroll to Top #34

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/web/src/components/Filter/Filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default function Filter({ findFilter, setFindFilter, onClose, isOpen }) {
}, []);

const handleIsShowReturned = useCallback(() => {
console.log("isShowReturned");
setFindFilter((prev) => ({
...prev,
isShowReturned: !prev.isShowReturned,
Expand Down
36 changes: 34 additions & 2 deletions packages/web/src/components/ResultsBar/ResultsBar.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useContext, useCallback, useState } from "react";
import { useContext, useCallback, useRef, useState } from "react";
import "./ResultsBar.css";
import ResultCard from "../ResultCard/ResultCard";
import { Box, Flex, Text, Button } from "@chakra-ui/react";
import { Box, Button, Flex, Text, IconButton } from "@chakra-ui/react";
import { ArrowUpIcon } from "@chakra-ui/icons"
import DataContext from "../../context/DataContext";
import { UserAuth } from "../../context/AuthContext";
import Fuse from "fuse.js";
Expand Down Expand Up @@ -65,6 +66,14 @@ export default function ResultsBar({
setItemsOnScreenLimit(itemsonScreenLimit + 10);
}, [itemsonScreenLimit]);

// scroll to the top of results bar
const handleScrollToTop = useCallback(() => {
boxRef.current.scrollTo({
top: 0,
behavior: 'smooth'
})
});

const loadMoreButton = (
<Button
onClick={handleLoadMore}
Expand All @@ -80,6 +89,27 @@ export default function ResultsBar({
</Button>
);

const boxRef = useRef(null);
const scrollToTopButton = (
<IconButton
isRound={true}
size={["md", "lg"]}
position="absolute"
top={["5%", "10%"]}
right={["10%", "20%"]}
// top={['5%', '10%']}
// right={['5%', '10%', '20%']}
onClick={handleScrollToTop}
variant={"solid"}
colorScheme="blue"
opacity={0.5}
_hover={{
opacity: "1"
}}
icon={<ArrowUpIcon/>}
/>
);

// Retrieve all items that meet the filter criteria

// Display only the first 10 items on the screen, all items if there are less than 10 items left to be loaded
Expand All @@ -99,6 +129,7 @@ export default function ResultsBar({

return (
<Box
ref={boxRef}
paddingX="5px"
width={{ base: "90vw", md: "21vw" }}
height="80vh"
Expand All @@ -107,6 +138,7 @@ export default function ResultsBar({
>
{allResults.length > 0 ? viewableResults : noResults}
{viewableResults.length < allResults.length && loadMoreButton}
{viewableResults.length > 10 && scrollToTopButton}
</Box>
);
}
1 change: 0 additions & 1 deletion packages/web/src/utils/Utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Define callback function to return filtered items (filtered according to search bar and filter markers)
const filterItem = (item, findFilter, user) => {
console.log(item);
return (
((findFilter.islost && item.islost) ||
(findFilter.isFound && !item.islost)) &&
Expand Down