diff --git a/client/message.coffee b/client/message.coffee index 4a8943ef..37aefeb8 100644 --- a/client/message.coffee +++ b/client/message.coffee @@ -4,6 +4,7 @@ import OverlayTrigger from 'react-bootstrap/OverlayTrigger' import Tooltip from 'react-bootstrap/Tooltip' import {useTracker} from 'meteor/react-meteor-data' import Blaze from 'meteor/gadicc:blaze-react-component' +import {useMediaQuery} from 'react-responsive' import useEventListener from '@use-it/event-listener' import {Credits} from './layout.coffee' @@ -207,6 +208,17 @@ Message = React.memo ({message}) -> undefined , [message.title] + ## Display table of contents according to whether screen is at least + ## Bootstrap 3's "sm" size, but allow user to override. + isScreenSm = useMediaQuery query: '(min-width: 768px)' + [toc, setToc] = useState() + useLayoutEffect -> + setToc isScreenSm + , [isScreenSm] + onToc = (e) -> + e.preventDefault() + setToc not toc + ## Set sticky column height to remaining height of screen: ## 100vh when stuck, and less when header is (partly) visible. stickyRef = useRef() @@ -215,22 +227,36 @@ Message = React.memo ({message}) -> stickyRef.current.style.height = "calc(100vh - #{rect.y}px)" if rect.height undefined , 100), [] - useEffect stickyHeight, [] # initialize + useEffect stickyHeight, [toc] # initialize useEventListener 'resize', stickyHeight useEventListener 'scroll', stickyHeight -
-
- - - - + <> + -
- +
+
+ + + + +
+ {if toc +
+ +
+ }
-
+ Message.displayName = 'Message' MessageInfoBoxes = React.memo ({message}) -> diff --git a/client/message.styl b/client/message.styl index 8a8dddb1..960017a5 100644 --- a/client/message.styl +++ b/client/message.styl @@ -114,6 +114,9 @@ bootstrap-3-button(bg-color) // based on mixins/buttons.less // TableOfContents +.toc-toggle + margin-top: -19.39px // rendered height, putting exactly into margin + nav.contents padding-bottom: 5px height: 100% // match parent height set in JavaScript diff --git a/package.json b/package.json index 5843c43d..a0e7f7f8 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "react-bootstrap-typeahead": "^5.1.4", "react-dom": "^17.0.1", "react-intersection-observer": "^8.31.0", + "react-responsive": "^8.2.0", "roman-numeral": "^0.2.6", "sanitize-html": "^1.27.5" },