Skip to content

Commit e04ceb9

Browse files
Pollepsjoepio
authored andcommitted
#770 Search results display more info
1 parent 438d05a commit e04ceb9

File tree

15 files changed

+136
-106
lines changed

15 files changed

+136
-106
lines changed

browser/data-browser/src/components/Card.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ type CardProps = {
1111
/** A Card with a border. */
1212
export const Card = styled.div<CardProps>`
1313
background-color: ${props => props.theme.colors.bg};
14-
/** Don't put side margins in this component - use a wrapping component */
15-
border: solid 1px ${props => props.theme.colors.bg2};
16-
box-shadow: ${props => props.theme.boxShadow};
14+
15+
border: solid 1px
16+
${props =>
17+
props.highlight ? props.theme.colors.main : props.theme.colors.bg2};
18+
box-shadow: ${props =>
19+
props.highlight
20+
? `0 0 0 1px ${props.theme.colors.main}, ${props.theme.boxShadow}`
21+
: props.theme.boxShadow};
22+
1723
padding: ${props => props.theme.margin}rem;
18-
/* margin-bottom: ${props => props.theme.margin}rem; */
19-
padding-bottom: 0;
2024
border-radius: ${props => props.theme.radius};
2125
max-height: ${props => (props.small ? '10rem' : 'none')};
2226
overflow: ${props => (props.small ? 'hidden' : 'visible')};
23-
border-color: ${props =>
24-
props.highlight ? props.theme.colors.main : props.theme.colors.bg2};
2527
2628
${p => transitionName('resource-page', p.about)};
2729
`;

browser/data-browser/src/components/Navigation.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ const NavBarBase = styled.div<NavBarStyledProps>`
166166
/** Width of the floating navbar in rem */
167167
const NavBarFloating = styled(NavBarBase)`
168168
box-shadow: ${props => props.theme.boxShadow};
169-
box-sizing: border-box;
170169
border-radius: 999px;
171170
overflow: hidden;
172171
max-width: calc(100% - 2rem);
@@ -179,6 +178,11 @@ const NavBarFloating = styled(NavBarBase)`
179178
top: ${props => (props.top ? '2rem' : 'auto')};
180179
bottom: ${props => (props.top ? 'auto' : '1rem')};
181180
181+
&:has(input:focus) {
182+
box-shadow: 0px 0px 0px 1px ${props => props.theme.colors.main};
183+
border-color: ${props => props.theme.colors.main};
184+
}
185+
182186
@media (max-width: ${props => props.theme.containerWidth}rem) {
183187
max-width: calc(100% - 1rem);
184188
left: auto;
@@ -198,6 +202,10 @@ const NavBarFixed = styled(NavBarBase)`
198202
props.top ? 'solid 1px ' + props.theme.colors.bg2 : 'none'};
199203
border-top: ${props =>
200204
!props.top ? 'solid 1px ' + props.theme.colors.bg2 : 'none'};
205+
206+
&:has(input:focus) {
207+
box-shadow: 0px 0px 0px 2px ${props => props.theme.colors.main};
208+
}
201209
`;
202210

203211
const SideBarWrapper = styled('div')`

browser/data-browser/src/components/PropVal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function PropVal({
6161
</PropertyLabel>
6262
</AtomicLink>
6363
{editable ? (
64-
<ValueForm resource={resource} propertyURL={propertyURL} noMargin />
64+
<ValueForm resource={resource} propertyURL={propertyURL} />
6565
) : (
6666
<ValueComp
6767
datatype={property.datatype}

browser/data-browser/src/components/Searchbar.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ const Input = styled.input`
159159
flex: 1;
160160
min-width: 1rem;
161161
background-color: ${props => props.theme.colors.bg};
162-
outline: 0;
162+
// Outline is handled by the Navbar.
163+
outline: none;
163164
color: ${p => p.theme.colors.textLight};
164165
`;
165166

@@ -172,9 +173,7 @@ const Form = styled.form`
172173
border-radius: 999px;
173174
174175
:hover {
175-
box-shadow: inset 0 0 0 2px
176-
${props => transparentize(0.6, props.theme.colors.main)};
177-
176+
${props => transparentize(0.6, props.theme.colors.main)};
178177
${Input} {
179178
color: ${p => p.theme.colors.text};
180179
}
@@ -183,8 +182,9 @@ const Form = styled.form`
183182
${Input} {
184183
color: ${p => p.theme.colors.text};
185184
}
185+
186+
// Outline is handled by the Navbar.
186187
outline: none;
187-
box-shadow: inset 0 0 0 2px ${props => props.theme.colors.main};
188188
}
189189
`;
190190

browser/data-browser/src/components/ValueComp.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ import { ErrMessage } from './forms/InputStyles';
1616
type Props = {
1717
value: JSONValue;
1818
datatype: Datatype;
19-
noMargin?: boolean;
2019
};
2120

2221
/** Renders a value in a fitting way, depending on its DataType */
23-
function ValueComp({ value, datatype, noMargin }: Props): JSX.Element {
22+
function ValueComp({ value, datatype }: Props): JSX.Element {
2423
try {
2524
switch (datatype) {
2625
case Datatype.ATOMIC_URL: {
@@ -36,7 +35,7 @@ function ValueComp({ value, datatype, noMargin }: Props): JSX.Element {
3635
case (Datatype.DATE, Datatype.TIMESTAMP):
3736
return <DateTime date={valToDate(value)} />;
3837
case Datatype.MARKDOWN:
39-
return <Markdown text={valToString(value)} noMargin={noMargin} />;
38+
return <Markdown text={valToString(value)} />;
4039
case Datatype.RESOURCEARRAY:
4140
return <ResourceArray subjects={valToArray(value)} />;
4241
default:

browser/data-browser/src/components/datatypes/Markdown.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,21 @@ import { styled } from 'styled-components';
33
import remarkGFM from 'remark-gfm';
44
import { Button } from '../Button';
55
import { truncateMarkdown } from '../../helpers/markdown';
6-
import { useState } from 'react';
6+
import { FC, useState } from 'react';
77

88
type Props = {
99
text: string;
10-
/**
11-
* By default, all bottom Markdown elements have some margin (e.g. the last
12-
* paragraph). If you set noMargin, this is corrected.
13-
*/
14-
noMargin?: boolean;
1510
renderGFM?: boolean;
1611
/**
1712
* If this is set, and the markdown is more characters than this number, the
1813
* text will be truncated and a button will be shown
1914
*/
2015
maxLength?: number;
16+
className?: string;
2117
};
2218

2319
/** Renders a markdown value */
24-
function Markdown({
25-
text,
26-
noMargin,
27-
renderGFM,
28-
maxLength,
29-
}: Props): JSX.Element | null {
20+
const Markdown: FC<Props> = ({ text, renderGFM, maxLength, className }) => {
3021
const [collapsed, setCollapsed] = useState(true);
3122

3223
maxLength = maxLength || 5000;
@@ -36,7 +27,7 @@ function Markdown({
3627
}
3728

3829
return (
39-
<MarkdownWrapper noMargin={noMargin}>
30+
<MarkdownWrapper className={className}>
4031
<ReactMarkdown remarkPlugins={renderGFM ? [remarkGFM] : []}>
4132
{collapsed ? truncateMarkdown(text, maxLength) : text}
4233
</ReactMarkdown>
@@ -47,19 +38,14 @@ function Markdown({
4738
)}
4839
</MarkdownWrapper>
4940
);
50-
}
41+
};
5142

5243
Markdown.defaultProps = {
5344
renderGFM: true,
5445
};
5546

56-
interface MarkdownWrapperProps {
57-
noMargin?: boolean;
58-
}
59-
60-
const MarkdownWrapper = styled.div<MarkdownWrapperProps>`
47+
const MarkdownWrapper = styled.div`
6148
/* Corrects the margin added by <p> and other HTML elements */
62-
margin-bottom: -${p => (p.noMargin ? p.theme.margin : 0)}rem;
6349
6450
width: 100%;
6551
overflow-x: hidden;

browser/data-browser/src/components/forms/ValueForm.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,13 @@ interface ValueFormProps {
2626
* also override it manually
2727
*/
2828
datatype?: Datatype;
29-
noMargin?: boolean;
3029
}
3130

3231
/**
3332
* A form for a single Value. Presents a normal value, but let's the user click
3433
* on a button to turn it into an input.
3534
*/
36-
export function ValueForm({
37-
resource,
38-
noMargin,
39-
propertyURL,
40-
datatype,
41-
}: ValueFormProps) {
35+
export function ValueForm({ resource, propertyURL, datatype }: ValueFormProps) {
4236
const [editMode, setEditMode] = useState(false);
4337
const property = useProperty(propertyURL);
4438
const [value] = useValue(resource, propertyURL);
@@ -86,11 +80,7 @@ export function ValueForm({
8680
if (!editMode) {
8781
return (
8882
<ValueFormWrapper>
89-
<ValueComp
90-
value={value}
91-
datatype={datatype || property.datatype}
92-
noMargin={noMargin}
93-
/>
83+
<ValueComp value={value} datatype={datatype || property.datatype} />
9484
<EditButton title='Edit value'>
9585
<FaEdit onClick={() => setEditMode(!editMode)} />
9686
</EditButton>

browser/data-browser/src/routes/SearchRoute.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ export function Search(): JSX.Element {
142142
{results.map((subject, index) => (
143143
<ResourceCard
144144
initialInView={index < 5}
145-
small
146145
subject={subject}
147146
key={subject}
148147
highlight={index === selectedIndex}

browser/data-browser/src/views/Card/BookmarkCard.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
import { urls, useString, useTitle } from '@tomic/react';
1+
import { urls, useString } from '@tomic/react';
22

33
import { styled } from 'styled-components';
4-
import { AtomicLink } from '../../components/AtomicLink';
54
import Markdown from '../../components/datatypes/Markdown';
65
import {
76
ExternalLink,
87
ExternalLinkVariant,
98
} from '../../components/ExternalLink';
109
import { CardViewProps } from './CardViewProps';
10+
import { ResourceCardTitle } from './ResourceCardTitle';
1111

1212
export function BookmarkCard({ resource }: CardViewProps): JSX.Element {
13-
const [title] = useTitle(resource);
1413
const [url] = useString(resource, urls.properties.bookmark.url);
1514
const [preview] = useString(resource, urls.properties.bookmark.preview);
1615

1716
return (
1817
<>
19-
<AtomicLink subject={resource.getSubject()}>
20-
<Title>{title}</Title>
21-
</AtomicLink>
18+
<ResourceCardTitle resource={resource} />
2219
<ExternalLink to={url!} variant={ExternalLinkVariant.Button}>
2320
Open site
2421
</ExternalLink>
@@ -31,13 +28,6 @@ export function BookmarkCard({ resource }: CardViewProps): JSX.Element {
3128
);
3229
}
3330

34-
const Title = styled.h2`
35-
white-space: nowrap;
36-
overflow: hidden;
37-
text-overflow: ellipsis;
38-
line-height: 1.2;
39-
`;
40-
4131
const MarkdownWrapper = styled.div`
4232
margin-top: ${p => p.theme.margin}rem;
4333
margin-inline: -${p => p.theme.margin}rem;

browser/data-browser/src/views/Card/CollectionCard.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { useArray, useString, useTitle, properties } from '@tomic/react';
1+
import { useArray, useString, core, collections } from '@tomic/react';
22
import { useState } from 'react';
33

44
import Markdown from '../../components/datatypes/Markdown';
5-
import { AtomicLink } from '../../components/AtomicLink';
65
import { CardInsideFull, CardRow } from '../../components/Card';
76
import { ResourceInline } from '../ResourceInline';
87
import { CardViewProps } from './CardViewProps';
98
import { Button } from '../../components/Button';
9+
import { ResourceCardTitle } from './ResourceCardTitle';
1010

1111
const MAX_COUNT = 5;
1212

@@ -15,9 +15,8 @@ const MAX_COUNT = 5;
1515
* (shortname) is rendered prominently at the top.
1616
*/
1717
function CollectionCard({ resource, small }: CardViewProps): JSX.Element {
18-
const [title] = useTitle(resource);
19-
const [description] = useString(resource, properties.description);
20-
const [members] = useArray(resource, properties.collection.members);
18+
const [description] = useString(resource, core.properties.description);
19+
const [members] = useArray(resource, collections.properties.members);
2120
const [showAll, setShowMore] = useState(false);
2221

2322
const tooMany = members.length > MAX_COUNT;
@@ -29,9 +28,7 @@ function CollectionCard({ resource, small }: CardViewProps): JSX.Element {
2928

3029
return (
3130
<>
32-
<AtomicLink subject={resource.getSubject()}>
33-
<h2>{title}</h2>
34-
</AtomicLink>
31+
<ResourceCardTitle resource={resource} />
3532
{description && <Markdown text={description} />}
3633
{!small && (
3734
<CardInsideFull>

0 commit comments

Comments
 (0)