mirror of
https://github.com/urbit/shrub.git
synced 2024-11-30 22:15:47 +03:00
embeds: converted to links for better usability
This commit is contained in:
parent
22d0d9557f
commit
286c6c28e5
@ -77,7 +77,7 @@ function GroupRoutes(props: { group: string; url: string }) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if(!graphKeys.has(`${ship.slice(1)}/${name}`)) {
|
if(!graphKeys.has(`${ship.slice(1)}/${name}`)) {
|
||||||
if(graphKeys.size > 0) {
|
if(graphKeys.size > 1) { // TODO: Better loading logic see https://github.com/urbit/landscape/issues/1063
|
||||||
return <Redirect
|
return <Redirect
|
||||||
to={toQuery(
|
to={toQuery(
|
||||||
{ auto: 'y', redir: location.pathname },
|
{ auto: 'y', redir: location.pathname },
|
||||||
|
@ -2,7 +2,7 @@ import { BaseAnchor, Box, Center, Col, Icon, Row, Text } from '@tlon/indigo-reac
|
|||||||
import { Association, GraphNode, resourceFromPath, GraphConfig } from '@urbit/api';
|
import { Association, GraphNode, resourceFromPath, GraphConfig } from '@urbit/api';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { useHistory, useLocation } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
getPermalinkForGraph, GraphPermalink as IGraphPermalink, parsePermalink
|
getPermalinkForGraph, GraphPermalink as IGraphPermalink, parsePermalink
|
||||||
} from '~/logic/lib/permalinks';
|
} from '~/logic/lib/permalinks';
|
||||||
@ -76,7 +76,6 @@ function GraphPermalink(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const { full = false, showOurContact, pending, graph, group, index, transcluded } = props;
|
const { full = false, showOurContact, pending, graph, group, index, transcluded } = props;
|
||||||
const history = useHistory();
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { ship, name } = resourceFromPath(graph);
|
const { ship, name } = resourceFromPath(graph);
|
||||||
const node = useGraphState(
|
const node = useGraphState(
|
||||||
@ -114,11 +113,6 @@ function GraphPermalink(
|
|||||||
const showTransclusion = Boolean(association && node && transcluded < 1);
|
const showTransclusion = Boolean(association && node && transcluded < 1);
|
||||||
const permalink = getPermalinkForGraph(group, graph, index);
|
const permalink = getPermalinkForGraph(group, graph, index);
|
||||||
|
|
||||||
const navigate = (e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
history.push(`/perma${permalink.slice(16)}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const [nodeGroupHost, nodeGroupName] = association?.group.split('/').slice(-2) ?? ['Unknown', 'Unknown'];
|
const [nodeGroupHost, nodeGroupName] = association?.group.split('/').slice(-2) ?? ['Unknown', 'Unknown'];
|
||||||
const [nodeChannelHost, nodeChannelName] = association?.resource
|
const [nodeChannelHost, nodeChannelName] = association?.resource
|
||||||
.split('/')
|
.split('/')
|
||||||
@ -141,15 +135,16 @@ function GraphPermalink(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Col
|
<Col
|
||||||
|
as={Link}
|
||||||
|
to={`/perma${permalink.slice(16)}`}
|
||||||
width="100%"
|
width="100%"
|
||||||
bg="white"
|
bg="white"
|
||||||
maxWidth={full ? null : '500px'}
|
maxWidth={full ? null : '500px'}
|
||||||
border={full ? null : '1'}
|
border={full ? null : '1'}
|
||||||
borderColor="lightGray"
|
borderColor="lightGray"
|
||||||
borderRadius={2}
|
borderRadius={2}
|
||||||
cursor="pointer"
|
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
navigate(e);
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{loading && association && !errored && Placeholder((association.metadata.config as GraphConfig).graph)}
|
{loading && association && !errored && Placeholder((association.metadata.config as GraphConfig).graph)}
|
||||||
@ -167,7 +162,6 @@ function GraphPermalink(
|
|||||||
showTransclusion={showTransclusion}
|
showTransclusion={showTransclusion}
|
||||||
icon={getModuleIcon((association.metadata.config as GraphConfig).graph as GraphModule)}
|
icon={getModuleIcon((association.metadata.config as GraphConfig).graph as GraphModule)}
|
||||||
title={association.metadata.title}
|
title={association.metadata.title}
|
||||||
permalink={permalink}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{association && isInSameResource && transcluded === 2 && !loading && (
|
{association && isInSameResource && transcluded === 2 && !loading && (
|
||||||
@ -176,7 +170,6 @@ function GraphPermalink(
|
|||||||
showTransclusion={showTransclusion}
|
showTransclusion={showTransclusion}
|
||||||
icon={getModuleIcon((association.metadata.config as GraphConfig).graph as GraphModule)}
|
icon={getModuleIcon((association.metadata.config as GraphConfig).graph as GraphModule)}
|
||||||
title={association.metadata.title}
|
title={association.metadata.title}
|
||||||
permalink={permalink}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{isInSameResource && transcluded !== 2 && !loading && <Row height='2' />}
|
{isInSameResource && transcluded !== 2 && !loading && <Row height='2' />}
|
||||||
@ -185,7 +178,6 @@ function GraphPermalink(
|
|||||||
icon="Groups"
|
icon="Groups"
|
||||||
showDetails={false}
|
showDetails={false}
|
||||||
title={graph.slice(5)}
|
title={graph.slice(5)}
|
||||||
permalink={permalink}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
@ -195,7 +187,6 @@ function GraphPermalink(
|
|||||||
function PermalinkDetails(props: {
|
function PermalinkDetails(props: {
|
||||||
title: string;
|
title: string;
|
||||||
icon: any;
|
icon: any;
|
||||||
permalink: string;
|
|
||||||
showTransclusion?: boolean;
|
showTransclusion?: boolean;
|
||||||
showDetails?: boolean;
|
showDetails?: boolean;
|
||||||
known?: boolean;
|
known?: boolean;
|
||||||
|
@ -1,24 +1,26 @@
|
|||||||
import { Box, Col, Icon, Row, Text } from '@tlon/indigo-react';
|
import { Box, Col, Icon, Row, Text } from '@tlon/indigo-react';
|
||||||
import React, { ReactElement, useCallback } from 'react';
|
import React, { ReactElement, useCallback } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { useModal } from '~/logic/lib/useModal';
|
import { useModal } from '~/logic/lib/useModal';
|
||||||
import useMetadataState, { usePreview } from '~/logic/state/metadata';
|
import useMetadataState, { usePreview } from '~/logic/state/metadata';
|
||||||
import { PropFunc } from '~/types';
|
import { PropFunc } from '~/types';
|
||||||
import { JoinGroup } from '../landscape/components/JoinGroup';
|
import { JoinGroup } from '../landscape/components/JoinGroup';
|
||||||
import { MetadataIcon } from '../landscape/components/MetadataIcon';
|
import { MetadataIcon } from '../landscape/components/MetadataIcon';
|
||||||
|
|
||||||
export function GroupLink(
|
type GroupLinkProps = {
|
||||||
props: {
|
|
||||||
resource: string;
|
resource: string;
|
||||||
detailed?: boolean;
|
detailed?: boolean;
|
||||||
} & PropFunc<typeof Row>
|
} & PropFunc<typeof Row>
|
||||||
): ReactElement {
|
|
||||||
const { resource, ...rest } = props;
|
export function GroupLink({
|
||||||
|
resource,
|
||||||
|
borderColor,
|
||||||
|
...rest
|
||||||
|
}: GroupLinkProps): ReactElement {
|
||||||
const name = resource.slice(6);
|
const name = resource.slice(6);
|
||||||
const joined = useMetadataState(
|
const joined = useMetadataState(
|
||||||
useCallback(s => resource in s.associations.groups, [resource])
|
useCallback(s => resource in s.associations.groups, [resource])
|
||||||
);
|
);
|
||||||
const history = useHistory();
|
|
||||||
|
|
||||||
const { modal, showModal } = useModal({
|
const { modal, showModal } = useModal({
|
||||||
modal: <JoinGroup autojoin={name} />
|
modal: <JoinGroup autojoin={name} />
|
||||||
@ -27,26 +29,31 @@ export function GroupLink(
|
|||||||
const { preview } = usePreview(resource);
|
const { preview } = usePreview(resource);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<>
|
||||||
maxWidth="500px"
|
|
||||||
cursor='pointer'
|
|
||||||
{...rest}
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
|
||||||
backgroundColor='white'
|
|
||||||
borderColor={props.borderColor}
|
|
||||||
>
|
|
||||||
{modal}
|
{modal}
|
||||||
<Row
|
<Row
|
||||||
width="100%"
|
{...rest}
|
||||||
|
as={Link}
|
||||||
|
to={joined ? `/~landscape/ship/${name}` : `/perma/group/${name}`}
|
||||||
|
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
if (e.metaKey || e.ctrlKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
showModal();
|
||||||
|
}}
|
||||||
flexShrink={1}
|
flexShrink={1}
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
|
width="100%"
|
||||||
|
maxWidth="500px"
|
||||||
py={2}
|
py={2}
|
||||||
pr={2}
|
pr={2}
|
||||||
onClick={
|
cursor='pointer'
|
||||||
joined ? () => history.push(`/~landscape/ship/${name}`) : showModal
|
backgroundColor='white'
|
||||||
}
|
borderColor={borderColor}
|
||||||
opacity={preview ? '1' : '0.6'}
|
opacity={preview ? '1' : '0.6'}
|
||||||
>
|
>
|
||||||
<MetadataIcon height={6} width={6} metadata={preview ? preview.metadata : { color: '0x0' , picture: '' }} />
|
<MetadataIcon height={6} width={6} metadata={preview ? preview.metadata : { color: '0x0' , picture: '' }} />
|
||||||
@ -70,6 +77,6 @@ export function GroupLink(
|
|||||||
</Box>
|
</Box>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Box>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user