Skip to content

Commit

Permalink
feat: allow to hide dapps behind dev mode
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz committed Aug 1, 2024
1 parent cf2c5fc commit c3ef436
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
57 changes: 37 additions & 20 deletions packages/context/SidebarProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import {
import { useAppDispatch } from "../store/store";
import { SIDEBAR_LIST } from "../utils/sidebar";

import { useDeveloperMode } from "@/hooks/useDeveloperMode";
import { getValuesFromId, SEPARATOR } from "@/utils/dapp-store";

export const useSidebar = () => {
const isSidebarExpanded = useSelector(selectSidebarExpanded);
const selectedApps = useSelector(selectCheckedApps);
const availableApps = useSelector(selectAvailableApps);
const [developerMode] = useDeveloperMode();
const dispatch = useAppDispatch();
// on mobile sidebar is not expanded on load
const isMobile = useIsMobile();
Expand Down Expand Up @@ -51,31 +53,46 @@ export const useSidebar = () => {
[key: string]: any;
};

selectedApps.map((element) => {
const { appId, groupKey } = getValuesFromId(element);
if (!availableApps[groupKey]) {
return;
}
const option = availableApps[groupKey].options[appId];
if (option === undefined) {
return;
}
selectedApps
.filter((element) => {
const { appId, groupKey } = getValuesFromId(element);
if (!availableApps[groupKey]) {
return false;
}
const option = availableApps[groupKey].options[appId];
if (option === undefined) {
return false;
}
if (option.devOnly && !developerMode) {
return false;
}
return true;
})
.map((element) => {
const { appId, groupKey } = getValuesFromId(element);
if (!availableApps[groupKey]) {
return;
}
const option = availableApps[groupKey].options[appId];
if (option === undefined) {
return;
}

dynamicAppsSelection[element] = SIDEBAR_LIST[option.id]
? SIDEBAR_LIST[option.id]
: {
id: option.id,
title: option.title,
route: option.route,
url: option.url,
icon: option.icon,
};
});
dynamicAppsSelection[element] = SIDEBAR_LIST[option.id]
? SIDEBAR_LIST[option.id]
: {
id: option.id,
title: option.title,
route: option.route,
url: option.url,
icon: option.icon,
};
});

dynamicAppsSelection["dappstore"] = SIDEBAR_LIST["DAppsStore"];

return dynamicAppsSelection;
}, [availableApps, selectedApps]);
}, [availableApps, selectedApps, developerMode]);

const toggleSidebar = () => {
dispatch(setSidebarExpanded(!isSidebarExpanded));
Expand Down
12 changes: 9 additions & 3 deletions packages/screens/DAppStore/components/RightRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { DAppBox } from "./DAppBox";
import { BrandText } from "@/components/BrandText";
import { SVGorImageIcon } from "@/components/SVG/SVGorImageIcon";
import { GridList } from "@/components/layout/GridList";
import { useDeveloperMode } from "@/hooks/useDeveloperMode";
import { selectAvailableApps } from "@/store/slices/dapps-store";
import { layout } from "@/utils/style/layout";
import { dAppType } from "@/utils/types/dapp-store";

export const RightRail = ({ searchInput }: { searchInput: string }) => {
const availableApps = useSelector(selectAvailableApps);
const { width } = useWindowDimensions();
const [developerMode] = useDeveloperMode();
const isMobile = width < 760;
return (
<View
Expand Down Expand Up @@ -53,10 +55,14 @@ export const RightRail = ({ searchInput }: { searchInput: string }) => {
noFixedHeight
keyExtractor={(item) => item.id}
data={Object.values(element.options).filter(
(option: dAppType) =>
option.title
(option: dAppType) => {
if (option.devOnly && !developerMode) {
return false;
}
return option.title
.toLowerCase()
.includes(searchInput.toLowerCase()),
.includes(searchInput.toLowerCase());
},
)}
minElemWidth={300}
renderItem={({ item: option }, elemWidth) => {
Expand Down
1 change: 1 addition & 0 deletions packages/screens/DAppStore/query/getFromFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export function getAvailableApps(): dAppGroup {
groupKey: "top-apps",
selectedByDefault: false,
alwaysOn: false,
devOnly: true,
},
toripunks: {
id: "toripunks",
Expand Down
1 change: 1 addition & 0 deletions packages/utils/types/dapp-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface dAppType {
selectedByDefault: boolean;
alwaysOn: boolean;
order?: number;
devOnly?: boolean;
}

export interface dAppGroup {
Expand Down

0 comments on commit c3ef436

Please sign in to comment.