Skip to content

Commit

Permalink
results bar scroll to top
Browse files Browse the repository at this point in the history
  • Loading branch information
rebecca-123 committed May 27, 2024
1 parent bb27d2c commit 88a6a80
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
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="lg"
position="absolute"
top="10%"
right="20%"
onClick={handleScrollToTop}
variant={"solid"}
colorScheme="blue"
// marginTop="10px"
// marginBottom="10px"
opacity={0.5}
_hover={{
opacity: "1"
}}
icon={<ArrowUpIcon boxSize={50} />}
/>
);

// 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

0 comments on commit 88a6a80

Please sign in to comment.