({
post,
}: ReadingDrawerProps)
| 167 | // band, so pulling the drawer up is scrolling the post page, and its heights |
| 168 | // are scroll positions. Everywhere else Read opens the link as it always did. |
| 169 | export function ReadingDrawer({ |
| 170 | post, |
| 171 | }: ReadingDrawerProps): ReactElement | null { |
| 172 | const router = useRouter(); |
| 173 | // Known at mount, not after a paint: a post page that arrives with its |
| 174 | // data (a production route) must open the drawer before its first frame. |
| 175 | const isPhone = useIsPhoneNow(); |
| 176 | const { value: isOptedOut, set: setOptedOut } = useSettingsBooleanFlag( |
| 177 | 'openLinksInAppOptOut', |
| 178 | ); |
| 179 | const { open, article, fromFeed } = useReading(); |
| 180 | const [isAvailable, setIsAvailable] = useState(false); |
| 181 | const [isMenuOpen, setIsMenuOpen] = useState(false); |
| 182 | const [, copyLink] = useCopyLink(); |
| 183 | const { displayToast } = useToastNotification(); |
| 184 | const { logEvent } = useLogContext(); |
| 185 | const headRef = useRef<HTMLDivElement>(null); |
| 186 | const probeRef = useRef<HTMLDivElement>(null); |
| 187 | const geometry = useRef<Geometry | null>(null); |
| 188 | const returnTo = useRef(0); |
| 189 | const openedAt = useRef(0); |
| 190 | const closedBy = useRef<CloseReason>(CloseReason.Back); |
| 191 | const logClose = useRef<() => void>(); |
| 192 | logClose.current = () => |
| 193 | logEvent({ |
| 194 | event_name: LogEvent.CloseReadingDrawer, |
| 195 | target_type: TargetType.Post, |
| 196 | target_id: post.id, |
| 197 | extra: JSON.stringify({ |
| 198 | duration_ms: Date.now() - openedAt.current, |
| 199 | closed_by: closedBy.current, |
| 200 | }), |
| 201 | }); |
| 202 | const arrived = useRef(false); |
| 203 | const linkAfterClose = useRef<string | null>(null); |
| 204 | const sink = useRef<() => void>(); |
| 205 | const rise = useRef<() => void>(); |
| 206 | const glide = useRef<(to: number) => void>(); |
| 207 | |
| 208 | useClientLayoutEffect(() => { |
| 209 | setIsAvailable(isPhone && !isOptedOut && supportsReading()); |
| 210 | }, [isPhone, isOptedOut]); |
| 211 | |
| 212 | const enter = useCallback( |
| 213 | (url: string, origin: OpenOrigin) => { |
| 214 | // A post arrived at for its article has no place to return to but |
| 215 | // its top. |
| 216 | arrived.current = origin === OpenOrigin.Feed; |
| 217 | returnTo.current = arrived.current ? 0 : window.scrollY; |
| 218 | openedAt.current = Date.now(); |
| 219 | closedBy.current = CloseReason.Back; |
| 220 | logEvent({ |
| 221 | event_name: LogEvent.OpenReadingDrawer, |
| 222 | target_type: TargetType.Post, |
| 223 | target_id: post.id, |
| 224 | extra: JSON.stringify({ origin }), |
| 225 | }); |
| 226 | postReading(ReadingAction.Open, { url, postId: post.id }); |
nothing calls this directly
no test coverage detected