-
Notifications
You must be signed in to change notification settings - Fork 4
bucket list, prod by m.v.novikov88 #1
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
0fae590
0ed8516
a6f47c0
1f57f66
56dde34
2799d52
2c824f8
8fae035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export const setMediaSize = (mediaSize) => ({ | ||
| type: "SET_MEDIA_SIZE", | ||
| mediaSize | ||
| }), | ||
| setMenuState = (menuIsOpen) => ({ | ||
| type: "SET_HEADER_MENU_STATE", | ||
| menuIsOpen | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,45 @@ | ||
| import React, { useState, useEffect } from 'react'; | ||
| import React, { useState, useEffect, useCallback } from 'react'; | ||
| import { NavLink } from "react-router-dom"; | ||
| import { useDispatch, useMappedState } from "redux-react-hook"; | ||
| import { setMenuState } from "../../../actions/app"; | ||
|
|
||
| const mapState = (state) => ({ | ||
| _app: state.app | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Слишком много идентификаторов с префиксом
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. да это есть, префикс я начал давать для actions(и для других некоторых переменных например как toast) т.к. функция(имя переменной) одна и та же(чтоб не было конфликтов имен). Тут да - надо что то придумать и придерживаться этого правила. |
||
| }); | ||
|
|
||
| export default function Header(props){ | ||
| export default function Header(){ | ||
|
|
||
| const { _app } = useMappedState(mapState); | ||
| const [ isOpen, setIsOpen ] = useState(false); | ||
| const small = useMedia("(max-width: 767px)"); | ||
| const [ small, setSmall ] = useState(_app.mediaSize === "mobile"); | ||
|
|
||
| useEffect(() => { | ||
| const content = document.querySelector('.page-content'); | ||
|
|
||
| if(content){ | ||
|
|
||
| if(isOpen && small){ | ||
| setTimeout(() => { | ||
| content.style.display = "none" | ||
| }, 1000); | ||
| }else{ | ||
| content.style.display = "block"; | ||
| } | ||
| const dispatch = useDispatch(); | ||
| const _setMenuState = useCallback((menuIsOpen) => dispatch(setMenuState(menuIsOpen))); | ||
|
|
||
| useEffect(() => { | ||
| const isSmall = _app.mediaSize === "mobile"; | ||
| setSmall(isSmall); | ||
|
|
||
| if(!isSmall){ | ||
| _setMenuState(false); | ||
| setIsOpen(false) | ||
| }else{ | ||
| setTimeout(() => { | ||
| _setMenuState(isOpen); | ||
| }, (isOpen ? 700 : 300)) | ||
| } | ||
| }); | ||
| }, [_app.mediaSize, _app.menuIsOpen, isOpen]); | ||
|
|
||
| function onMenuClickHandler(){ | ||
| setIsOpen(!isOpen); | ||
| }; | ||
| } | ||
|
|
||
| function onLinkClickHandler(){ | ||
| setIsOpen(false); | ||
| }; | ||
| } | ||
|
|
||
| return ( | ||
| <header className={"header " + (small ? "mobile" : "")}> | ||
| <header className={"header " + _app.mediaSize}> | ||
| <div className="content-container"> | ||
| <div className="header-content"> | ||
|
|
||
|
|
@@ -74,20 +81,4 @@ export default function Header(props){ | |
| </div> | ||
| </header> | ||
| ); | ||
| } | ||
|
|
||
| function useMedia(query){ | ||
| const [matches, setMatches] = useState(window.matchMedia(query).matches); | ||
|
|
||
| useEffect(() => { | ||
| const media = window.matchMedia(query); | ||
| if (media.matches !== matches) setMatches(media.matches); | ||
|
|
||
| const listener = () => setMatches(media.matches); | ||
| window.addEventListener("resize", listener); | ||
| return () => window.removeEventListener("resize", listener); | ||
|
|
||
| }, [query]); | ||
|
|
||
| return matches; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.