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

Add redFlags filter #189

Merged
merged 2 commits into from
Jul 26, 2024
Merged
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
6 changes: 4 additions & 2 deletions src/components/ChainList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ export const ChainList = () => {
}
status
faucets
redFlags
}
}
}
`);

const chains = data.allChain.nodes;

const { query, showTestnets, showDeprecated } = useContext(SearchContext);
const { query, showTestnets, showDeprecated, showFlagged } = useContext(SearchContext);
const lowerCaseQuery = query.toLowerCase();

const handleFiltering = (chain) => {
Expand All @@ -48,7 +49,8 @@ export const ChainList = () => {
!showTestnets &&
(chain.faucets.length > 0 || lowerCaseName.includes("testnet"));
const isDeprecated = !showDeprecated && chain.status === "deprecated";
if (isTestnet || isDeprecated) {
const isFlagged = !showFlagged && chain.redFlags?.length > 0;
if (isTestnet || isDeprecated || isFlagged) {
return false;
}
if (query.length > 0) {
Expand Down
23 changes: 22 additions & 1 deletion src/components/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { FaFilter } from "react-icons/fa";
import { SearchContext } from "../context/SearchContext";

export const Filters = () => {
const { showTestnets, showDeprecated, setShowTestnets, setShowDeprecated } =
const { showTestnets, showDeprecated, showFlagged, setShowTestnets, setShowDeprecated, setShowFlagged } =
useContext(SearchContext);

const handleTestnetsToggle = () => {
Expand All @@ -28,6 +28,10 @@ export const Filters = () => {
setShowDeprecated((state) => !state);
};

const handleFlaggedToggle = () => {
setShowFlagged((state) => !state);
};

return (
<Popover>
<Tooltip label="Filters">
Expand Down Expand Up @@ -64,6 +68,7 @@ export const Filters = () => {
display="flex"
alignItems="center"
justifyContent="space-between"
mb="2"
>
<FormLabel htmlFor="deprecated-switch" mb="0">
Show Deprecated
Expand All @@ -74,6 +79,22 @@ export const Filters = () => {
isChecked={showDeprecated}
/>
</FormControl>

<FormControl
display="flex"
alignItems="center"
justifyContent="space-between"
>
<FormLabel htmlFor="flagged-switch" mb="0">
Show Flagged
</FormLabel>
<Switch
id="flagged-switch"
onChange={handleFlaggedToggle}
isChecked={showFlagged}
/>
</FormControl>

</PopoverBody>
</PopoverContent>
</Portal>
Expand Down
10 changes: 8 additions & 2 deletions src/context/SearchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ export const SearchProvider = ({ children }) => {
defaults?.showDeprecated ?? false
);

const [showFlagged, setShowFlagged] = useState(
defaults?.showFlagged ?? false
);

useEffect(() => {
const str = JSON.stringify({ showTestnets, showDeprecated });
const str = JSON.stringify({ showTestnets, showDeprecated, showFlagged });
window.localStorage.setItem(LOCALSTORAGE_KEY, str);
}, [showTestnets, showDeprecated]);
}, [showTestnets, showDeprecated, showFlagged]);

return (
<SearchContext.Provider
Expand All @@ -39,6 +43,8 @@ export const SearchProvider = ({ children }) => {
setShowTestnets,
showDeprecated,
setShowDeprecated,
showFlagged,
setShowFlagged
}}
>
{children}
Expand Down
Loading