Skip to content

Commit

Permalink
Pull logic into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed May 22, 2024
1 parent addd9fe commit 072e40b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/SidebarBottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const filterError: API_FilterFunction = ({ status }) => status?.[ADDON_ID]?.stat
const filterBoth: API_FilterFunction = ({ status }) =>
status?.[ADDON_ID]?.status === "warn" || status?.[ADDON_ID]?.status === "error";

const getFilter = (showWarnings = false, showErrors = false) => {
if (showWarnings && showErrors) return filterBoth;
if (showWarnings) return filterWarn;
if (showErrors) return filterError;
return filterNone;
};

const Wrapper = styled.div({
display: "flex",
gap: 5,
Expand All @@ -35,9 +42,7 @@ export const SidebarBottom = ({ api }: SidebarBottomProps) => {
const toggleErrors = useCallback(() => setShowErrors((shown) => !shown), []);

useEffect(() => {
let filter = filterNone;
if (hasWarnings && showWarnings) filter = filterWarn;
if (hasErrors && showErrors) filter = filter === filterWarn ? filterBoth : filterError;
const filter = getFilter(hasWarnings && showWarnings, hasErrors && showErrors);
api.experimental_setFilter(ADDON_ID, filter);
api.emit(ENABLE_FILTER, filter);
}, [api, hasWarnings, hasErrors, showWarnings, showErrors]);
Expand Down

0 comments on commit 072e40b

Please sign in to comment.