From ec678118233531b122b9725351e43f974a99c4f5 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 24 Dec 2022 22:26:43 +0800 Subject: [PATCH] Smart status heading + tap to scroll to hero status I'll probably need to componentize relative-time, it's getting not DRY --- src/pages/status.css | 29 ++++++++++++++++++++++++++++ src/pages/status.jsx | 46 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/pages/status.css diff --git a/src/pages/status.css b/src/pages/status.css new file mode 100644 index 00000000..74ae38e0 --- /dev/null +++ b/src/pages/status.css @@ -0,0 +1,29 @@ +.status-deck header h1 { + grid-column: 1 / 3; +} +.status-deck header { + display: flex; + align-items: center; + white-space: nowrap; +} +.status-deck header h1 { + min-width: 0; + flex-grow: 1; + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; +} + +.status-deck header.inview h1 { + font-weight: bold; +} + +.hero-heading { + font-size: 16px; + pointer-events: none; + display: inline-block; + margin-bottom: 0.25em; +} +.hero-heading .insignificant { + font-weight: normal; +} diff --git a/src/pages/status.jsx b/src/pages/status.jsx index 9b958a14..35120f9a 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -1,3 +1,5 @@ +import './status.css'; + import debounce from 'just-debounce-it'; import { Link } from 'preact-router/match'; import { @@ -7,15 +9,18 @@ import { useRef, useState, } from 'preact/hooks'; +import { InView } from 'react-intersection-observer'; import { useSnapshot } from 'valtio'; import Icon from '../components/icon'; import Loader from '../components/loader'; +import NameText from '../components/name-text'; import Status from '../components/status'; import htmlContentLength from '../utils/html-content-length'; import shortenNumber from '../utils/shorten-number'; import states from '../utils/states'; import store from '../utils/store'; +import useDebouncedCallback from '../utils/useDebouncedCallback'; import useTitle from '../utils/useTitle'; const LIMIT = 40; @@ -243,6 +248,9 @@ function StatusPage({ id }) { const hasManyStatuses = statuses.length > LIMIT; const hasDescendants = statuses.some((s) => s.descendant); + const [heroInView, setHeroInView] = useState(true); + const onView = useDebouncedCallback(setHeroInView, 100); + return (
@@ -252,13 +260,43 @@ function StatusPage({ id }) { statuses.length > 1 ? 'padded-bottom' : '' }`} > -
+
{ + if ( + !/^(a|button)$/i.test(e.target.tagName) && + heroStatusRef.current + ) { + heroStatusRef.current.scrollIntoView({ + behavior: 'smooth', + block: 'start', + }); + } + }} + > {/*
*/} -

Status

+

+ {!heroInView && heroStatus ? ( + + {' '} + + •{' '} + + + + ) : ( + 'Status' + )} +