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

Filter by cost fix #37

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 13 additions & 10 deletions src/comps/context/ThemeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ import {

const ThemeContext = React.createContext({
toggleColorMode: () => {},
colorMode: false
colorMode: false,
});

const ThemeProvider = (props) => {
// dark mode detection/toggles/context may become obsolete in a new version of MUI with the <CssVarsProvider> component
// using a home-made solution for now since it's still marked experimental
const browserPreference = useMediaQuery("(prefers-color-scheme: dark)");
const [storedPreference, setStoredPreference] = React.useState(window.localStorage.getItem("mode"));
const prefersDarkMode = storedPreference !== null ? storedPreference === "dark" : browserPreference;
const [storedPreference, setStoredPreference] = React.useState(
window.localStorage.getItem("mode")
);
const prefersDarkMode =
storedPreference !== null ? storedPreference === "dark" : browserPreference;
const toggle = React.useMemo(
() => () =>
setStoredPreference(() => {
const output = prefersDarkMode ? "light" : "dark";
window.localStorage.setItem("mode", output); // persist in localStorage
return output;
}),
[prefersDarkMode]
() => () =>
setStoredPreference(() => {
const output = prefersDarkMode ? "light" : "dark";
window.localStorage.setItem("mode", output); // persist in localStorage
return output;
}),
[prefersDarkMode]
);

const theme = React.useMemo(
Expand Down
20 changes: 15 additions & 5 deletions src/comps/ui/NavDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ import MenuRoundedIcon from "@mui/icons-material/MenuRounded";
import LogoutRoundedIcon from "@mui/icons-material/LogoutRounded";
import AdminPanelSettingsIcon from "@mui/icons-material/AdminPanelSettings";

import { Drawer, IconButton, List, ListItem, ListItemButton, ListItemIcon, ListItemText } from "@mui/material";
import {
Drawer,
IconButton,
List,
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
} from "@mui/material";
import NavBarLink from "./NavBarLink.js";
import { Brightness4, Brightness7 } from "@mui/icons-material";
import { ThemeContext } from "../context/ThemeProvider";
Expand Down Expand Up @@ -86,11 +94,13 @@ const NavDrawer = ({ user }) => {
</>
)}
<ListItem disablePadding={true}>
<ListItemButton
onClick={theme.toggleColorMode}
>
<ListItemButton onClick={theme.toggleColorMode}>
<ListItemIcon>
{ theme.colorMode === "light" ? <Brightness4 /> : <Brightness7 /> }
{theme.colorMode === "light" ? (
<Brightness4 />
) : (
<Brightness7 />
)}
</ListItemIcon>
<ListItemText primary={`Toggle dark mode`} />
</ListItemButton>
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import reportWebVitals from "./reportWebVitals";
const root = createRoot(document.getElementById("root"));

root.render(
<React.StrictMode>
<App />
</React.StrictMode>
<React.StrictMode>
<App />
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
Expand Down
16 changes: 15 additions & 1 deletion src/pages/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const Catalog = () => {

const user = useContext(UserContext);
const [maxCost, setMaxCost] = useState(10000);
const [costInput, setCostInput] = useState(10000);

// uses ? parameters as search params, targeting `q` as the search engine query key
let [searchParams] = useSearchParams(); // TODO: filter data server-side in the GraphQL query
Expand Down Expand Up @@ -123,9 +124,20 @@ const Catalog = () => {
// };

const handleInputChange = (event) => {
setCostInput(event.target.value === "" ? 0 : Number(event.target.value));
};

const handleInputBlur = (event) => {
setMaxCost(event.target.value === "" ? 0 : Number(event.target.value));
};

const handleKeyDownPress = (event) => {
if (event.keyCode === 13) {
// enter
handleInputBlur(event);
}
};

// Get array of eligibility names
const eligibilities_response = useQuery(ELIGIBILITY_QUERY);
const categories_response = useQuery(CATEGORY_QUERY);
Expand Down Expand Up @@ -451,9 +463,11 @@ const Catalog = () => {
<Grid item xs={12} sm={4} md={4} lg={4} xl={4}>
<Input
autoFocus
value={maxCost}
value={costInput}
size="small"
onChange={handleInputChange}
onBlur={handleInputBlur}
onKeyDown={handleKeyDownPress}
/>
</Grid>
{/*<Button*/}
Expand Down