diff --git a/public/js/smoothscroll.min.js b/public/js/smoothscroll.min.js new file mode 100644 index 0000000..3ab7669 --- /dev/null +++ b/public/js/smoothscroll.min.js @@ -0,0 +1,10 @@ +/* +Copyright (c) 2018 LieutenantPeacock + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +!function(t){var e,n=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e){t.setTimeout(e,1e3/60)},o=[],r=document.getElementsByTagName("html")[0];function i(n){var o=n.getBoundingClientRect(),i=t.pageYOffset||r.scrollTop||e.scrollTop,l=t.pageXOffset||r.scrollLeft||e.scrollLeft,s=r.clientTop||e.clientTop||0,a=r.clientLeft||e.clientLeft||0;return{top:o.top+i-s,left:o.left+l-a}}function l(t){return/Element/.test({}.toString.call(t))}function s(t,e,n){var o;if("number"==typeof t)return t;switch(t){case"start":o=0;break;case"end":o=n+10;break;case"center":o=n/2;break;default:var r,i=t.split("+"),l=t.split("-");if(t.indexOf("+")>0)throw new Error("Position can only contain a + sign at the start");if(t.indexOf("-")>0)throw new Error("Position can only contain a - sign at the start");if(t.indexOf("+")>-1&&t.indexOf("-")>-1)throw new Error("Position cannot contain both + and - signs.");if(t.indexOf("%")>-1&&t.indexOf("%")!==t.length-1)throw new Error("Position can only contain a % symbol at the end.");o=i[1]?(r=i[1]).indexOf("%")>-1?e+n*(r=r.split("%")[0])/100:e+ +r:l[1]?(r=l[1]).indexOf("%")>-1?e-n*(r=r.split("%")[0])/100:e-+r:t.indexOf("%")>-1?n*(r=t.split("%")[0])/100:+t}return o}function a(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent&&t.attachEvent("on"+e,n)}function c(t,e,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent&&t.detachEvent("on"+e,n)}var u={duration:500,preventUserScroll:!0,scrollEvents:["scroll","mousedown","wheel","DOMMouseScroll","mousewheel","touchmove"],scrollKeys:[37,38,39,40,32],allowAnimationOverlap:!1,easing:"linear"};function f(){for(var t=0;t-1&&t.split("%").length<3)return r(+t.split("%")[0]/100);throw new Error("Invalid block or inline string value")}}function h(e,n){if(t.getComputedStyle){var o=getComputedStyle(e,null);if(o.getPropertyValue)return o.getPropertyValue(n);if(o.getAttribute)return o.getAttribute(n);if(o[n])return o[n]}else if(e.currentStyle)return e.currentStyle[n]}function m(e){return e?{x:e.scrollLeft,y:e.scrollTop}:{x:void 0!==t.pageXOffset?t.pageXOffset:(document.documentElement||document.body.parentNode||document.body).scrollLeft,y:void 0!==t.pageYOffset?t.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop}}function p(t,e,n){return t>e?e-(e-t)*n:(t-e)*n+e}function g(t){for(var e=o.length,n=e-1;n>=0;n--)if(t){var r=o[n];t(r)&&r.destroy(!0)}else o[n].destroy(!0);return!!e}t.smoothScroll=function v(w){if(e||(e=document.getElementsByTagName("body")[0]),w=w||{},this instanceof v)return{smoothScroll:function(e){e=e||{};for(var n=0;n=O)if(y("y"!=q?S:T,"x"!=q?M:L),null!=q&&++Y<2){switch(q){case"x":q="y",T=S;break;case"y":q="x",L=M}E=null}else nt(!1,!1)},nt,!f(w.allowAnimationOverlap,u.allowAnimationOverlap),W)}function _(){et(),nt(!0,!1)}function tt(t){D.indexOf(t.keyCode)>-1&&(et(),nt(!0,!1))}function et(){for(var t=0;t +
diff --git a/src/app/(pages)/shows/shows.module.scss b/src/app/(pages)/shows/shows.module.scss index 76987b7..a819925 100644 --- a/src/app/(pages)/shows/shows.module.scss +++ b/src/app/(pages)/shows/shows.module.scss @@ -11,7 +11,6 @@ .calendar { width: 90%; position: relative; - display: flex; flex-direction: column; align-items: flex-end; } @@ -106,6 +105,11 @@ display: none; } +.scroll_to_top { + @extend .styled_button; + display: none; +} + @media (hover: none), (max-width: 1000px) { .day_buttons { display: flex; @@ -165,6 +169,17 @@ .shows, .days { width: 100%; } + .scroll_to_top { + display: block; + font-size: 1.25rem; + font-family: unset; + position: sticky; + background-color: var(--bg2-color); + top: 0.5rem; + left: 0.5rem; + z-index: 3; + margin: 0; + } } .hover_card p { @@ -216,4 +231,4 @@ height: 0; z-index: -1; border-bottom: 0.25rem dotted var(--text-light-color); -} +} \ No newline at end of file diff --git a/src/app/(pages)/shows/static.tsx b/src/app/(pages)/shows/static.tsx index 07d4540..be33acb 100644 --- a/src/app/(pages)/shows/static.tsx +++ b/src/app/(pages)/shows/static.tsx @@ -1,6 +1,7 @@ import { formatTime, formatTimes, getWeekdayString } from "@/app/utils/time"; import styles from "./shows.module.scss"; -import { MutableRefObject } from "react"; +import { MutableRefObject, useEffect, useRef } from "react"; +import { isClient } from "@/app/utils/is_client"; export type Show = {name: string, desc: string, hosts: string, poster: string, start_time: number, end_time: number, day: number, is_running: number}; export type Day = {day: number, dayName: string, shows: Show[]}; @@ -51,7 +52,18 @@ export function renderShows(days: Day[], dayStarts: MutableRefObject = null; + if(isClient()){ + top = useRef(null); + } + function scrollToTop() { + if(top == null || top.current == null) { + return; + } + (window as any).smoothScroll({toElement: top.current, duration: 300, easing: (window as any).smoothScroll.easing.easeOutBack}); } return ( @@ -64,13 +76,14 @@ export function renderShows(days: Day[], dayStarts: MutableRefObject )}
-
+
{Array.apply(null, Array(5)).map((_, i) => )}
+
{days.map((day) => diff --git a/src/app/utils/is_client.ts b/src/app/utils/is_client.ts new file mode 100644 index 0000000..2ade281 --- /dev/null +++ b/src/app/utils/is_client.ts @@ -0,0 +1,4 @@ +// https://stackoverflow.com/questions/32216383/in-react-how-do-i-detect-if-my-component-is-rendering-from-the-client-or-the-se +export function isClient(): boolean { + return (typeof window !== 'undefined' && !!window.document && !!window.document.createElement); +} \ No newline at end of file