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

feat: feature flags added to dev mode #133

Merged
merged 8 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 4 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
} from "./pages";
import ResponsiveAppBar from "./components/ResponsiveAppBar";
import DevModeContext from "./contexts/devMode";
import {
getIsDevMode, getVisiblePages,
} from "./localeStorageManager";
import { getIsDevMode, getVisiblePages } from "./localeStorageManager";
import LoginContext from "./contexts/login";
import off from "./off";

Expand Down Expand Up @@ -51,7 +49,7 @@ const theme = createTheme({

export default function App() {
const [devMode, setDevMode] = React.useState(getIsDevMode);
const visiblePages = getVisiblePages();
const [visiblePages, setVisiblePages] = React.useState(getVisiblePages);
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
const [userState, setUserState] = React.useState({
userName: "",
isLoggedIn: false,
Expand Down Expand Up @@ -113,7 +111,8 @@ export default function App() {
value={{
devMode,
setDevMode,
visiblePages
visiblePages,
setVisiblePages,
}}
>
<CssBaseline />
Expand Down
8 changes: 7 additions & 1 deletion src/localeStorageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ export const getIsDevMode = () => {

export const getVisiblePages = () => {
const settings = localSettings.fetch();
return settings[localSettingsKeys.visiblePages] ?? { nutriscore: true, insights: true};
console.log({ settings });
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
return (
settings[localSettingsKeys.visiblePages] ?? {
nutriscore: true,
insights: true,
}
);
};

/** Questions page: returns a boolean for hiding the images. Uses local storage. */
Expand Down
16 changes: 8 additions & 8 deletions src/pages/settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ export default function Settings() {

const [language, setLanguage] = React.useState(i18n.language);

const { devMode, setDevMode, visiblePages } =
const { devMode, setDevMode, visiblePages, setVisiblePages } =
React.useContext(DevModeContext);

const handleDevModeChange = (event) => {
localSettings.update(localSettingsKeys.isDevMode, event.target.checked);
setDevMode(event.target.checked);
Object.keys(visiblePages).forEach((pageUrl)=>{
visiblePages[pageUrl]=event.target.checked
localSettings.update(localSettingsKeys.visiblePages[pageUrl], event.target.checked);
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't care about that, the pages will just appear as they was before. Not a problem

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this so that when devmode is switched on, regardless of the previous states, both nutrition and insights will be turned on

};

const handleVisiblePagesChange = (event, pageUrl) => {
localSettings.update(localSettingsKeys.pageUrl, event.target.checked);
visiblePages[pageUrl] = event.target.checked;
const handleVisiblePagesChange = (pageUrl) => (event) => {
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
const newVisiblePages = {
...visiblePages,
[pageUrl]: event.target.checked,
};
localSettings.update(localSettingsKeys.visiblePages, newVisiblePages);
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
setVisiblePages(newVisiblePages);
};

const handleLangChange = (e) => {
Expand Down