Skip to content

Commit

Permalink
reset search and categories on network select
Browse files Browse the repository at this point in the history
  • Loading branch information
simkasss committed Aug 15, 2023
1 parent 545902f commit 1d2d44a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/features/feeds/components/FeedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const FeedList = ({
const [selectedFeedCategories, setSelectedFeedCategories] = useQueryString("categories", [])
const [showCategoriesDropdown, setShowCategoriesDropdown] = useState<boolean>(false)
const [showExtraDetails, setShowExtraDetails] = useState(false)
const [currentPage, setCurrentPage] = useState(1)
const [currentPage, setCurrentPage] = useQueryString("page", 1)
const paginate = (pageNumber) => setCurrentPage(pageNumber)
const addrPerPage = 8
const lastAddr = currentPage * addrPerPage
Expand All @@ -39,13 +39,21 @@ export const FeedList = ({

function handleNetworkSelect(chain: Chain) {
setSelectedChain(chain.page)
setSearchValue("")
setSelectedFeedCategories([])
setCurrentPage(1)
}

const handleCategorySelection = (category) => {
paginate(1)
if (selectedFeedCategories.includes(category)) {
if (typeof selectedFeedCategories === "string" && selectedFeedCategories !== category) {
setSelectedFeedCategories([selectedFeedCategories, category])
} else if (typeof selectedFeedCategories === "string" && selectedFeedCategories === category) {
setSelectedFeedCategories([])
}
if (Array.isArray(selectedFeedCategories) && selectedFeedCategories.includes(category)) {
setSelectedFeedCategories(selectedFeedCategories.filter((item) => item !== category))
} else {
} else if (Array.isArray(selectedFeedCategories)) {
setSelectedFeedCategories([...selectedFeedCategories, category])
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/features/feeds/components/Tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import feedList from "./FeedList.module.css"
import { clsx } from "../../../lib"
import { ChainNetwork } from "~/features/data/chains"
import tableStyles from "./Tables.module.css"
import button from "@chainlink/design-system/button.module.css"
import { CheckHeartbeat } from "./pause-notice/CheckHeartbeat"
import { monitoredFeeds, FeedDataItem } from "~/features/data"

Expand Down Expand Up @@ -67,7 +68,7 @@ const Pagination = ({ addrPerPage, totalAddr, paginate, currentPage, firstAddr,
className={button.secondary}
style={"outline-offset: 2px"}
disabled={currentPage === 1}
onClick={() => paginate(currentPage - 1)}
onClick={() => paginate(Number(currentPage) - 1)}
>
Prev
</button>
Expand All @@ -78,7 +79,7 @@ const Pagination = ({ addrPerPage, totalAddr, paginate, currentPage, firstAddr,
className={button.secondary}
style={"outline-offset: 2px"}
disabled={lastAddr >= totalAddr}
onClick={() => paginate(currentPage + 1)}
onClick={() => paginate(Number(currentPage) + 1)}
>
Next
</button>
Expand Down Expand Up @@ -369,7 +370,6 @@ export const MainnetTable = ({
.includes(searchValue.toLowerCase().replaceAll(" ", "")) ||
pair.docs.porSource?.toLowerCase().replaceAll(" ", "").includes(searchValue.toLowerCase().replaceAll(" ", ""))
)
console.log("filteredMetadata", filteredMetadata)
const slicedFilteredMetadata = filteredMetadata.slice(firstAddr, lastAddr)
return (
<div>
Expand Down

0 comments on commit 1d2d44a

Please sign in to comment.