Merge pull request #4755 from urbit/lf/scroll-pos-reset-publish

landscape: grabbag
This commit is contained in:
matildepark 2021-04-12 19:45:42 -04:00 committed by GitHub
commit 26e70d8550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 14 deletions

View File

@ -31,6 +31,6 @@ export function getNotificationCount(
): number {
const unread = unreads.graph?.[path] || {};
return Object.keys(unread)
.map(index => unread[index]?.notifications || 0)
.map(index => unread[index]?.notifications?.length || 0)
.reduce(f.add, 0);
}

View File

@ -1,10 +1,10 @@
import React from 'react';
import React, {useEffect, useRef} from 'react';
import { Box } from '@tlon/indigo-react';
import GlobalApi from '~/logic/api/global';
import { StoreState } from '~/logic/store/type';
import { Association } from '@urbit/api';
import { RouteComponentProps } from 'react-router-dom';
import { RouteComponentProps, useLocation } from 'react-router-dom';
import { NotebookRoutes } from './components/NotebookRoutes';
type PublishResourceProps = StoreState & {
@ -17,9 +17,21 @@ export function PublishResource(props: PublishResourceProps) {
const { association, api, baseUrl, notebooks } = props;
const rid = association.resource;
const [, , ship, book] = rid.split('/');
const location = useLocation();
const scrollRef = useRef(null)
useEffect(() => {
const search = new URLSearchParams(location.search);
if(search.has('selected') || search.has('edit') || !scrollRef.current) {
return;
}
scrollRef.current.scrollTop = 0;
}, [location])
return (
<Box height="100%" width="100%" overflowY="auto">
<Box ref={scrollRef} height="100%" width="100%" overflowY="auto">
<NotebookRoutes
api={api}
ship={ship}

View File

@ -94,12 +94,6 @@ export function Note(props: NoteProps & RouteComponentProps) {
const { doCopy, copyDisplay } = useCopy(permalink, 'Copy Link');
const windowRef = React.useRef(null);
useEffect(() => {
if (windowRef.current && !query.has('selected')) {
windowRef.current.parentElement.scrollTop = 0;
}
}, [note, windowRef]);
return (
<Box
@ -112,7 +106,6 @@ export function Note(props: NoteProps & RouteComponentProps) {
width="100%"
gridRowGap={4}
mx="auto"
ref={windowRef}
>
<Link to={rootUrl}>
<Text>{'<- Notebook Index'}</Text>

View File

@ -135,7 +135,7 @@ return;
return (
<Row
alignItems="center"
maxWidth="20rem"
maxWidth="min(100%, 20rem)"
gapX="1" borderRadius="1" backgroundColor="washedGray">
{ textOnly && (<Icon ml="2" display="block" icon="ArrowExternal" />)}
<BaseAnchor
@ -149,8 +149,8 @@ return;
textOverflow="ellipsis"
minWidth="0"
width={textOnly ? "calc(100% - 24px)" : "fit-content"}
maxWidth="min(500px, 100%)"
style={{ color: 'inherit', textDecoration: 'none', ...style }}
className="word-break-all"
target="_blank"
rel="noopener noreferrer"
>
@ -218,6 +218,8 @@ return;
style={style}
onLoad={onLoad}
objectFit="contain"
height="100%"
width="100%"
{...audioProps}
{...props}
/>
@ -237,6 +239,8 @@ return;
style={style}
onLoad={onLoad}
objectFit="contain"
height="100%"
width="100%"
{...videoProps}
{...props}
/>

View File

@ -157,7 +157,7 @@ export function ShipSearch<I extends string, V extends Value<I>>(
setFieldValue(name(), newValue);
};
const error = _.compact(errors[id] as string[]);
const error = _.compact((_.isString(errors[id]) ? [errors[id]] : errors[id] as string[]) as any);
const isExact = useCallback((s: string) => {
const ship = `~${deSig(s)}`;