Skip to content

Commit fd94933

Browse files
Pollepsjoepio
authored andcommitted
#770 Fix padding issue
1 parent 11ec1f1 commit fd94933

File tree

7 files changed

+86
-36
lines changed

7 files changed

+86
-36
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import {
88
} from '../../components/ExternalLink';
99
import { CardViewProps } from './CardViewProps';
1010
import { ResourceCardTitle } from './ResourceCardTitle';
11+
import { Column } from '../../components/Row';
1112

1213
export function BookmarkCard({ resource }: CardViewProps): JSX.Element {
1314
const [url] = useString(resource, urls.properties.bookmark.url);
1415
const [preview] = useString(resource, urls.properties.bookmark.preview);
1516

1617
return (
17-
<>
18+
<Column gap='0.5rem'>
1819
<ResourceCardTitle resource={resource} />
1920
<ExternalLink to={url!} variant={ExternalLinkVariant.Button}>
2021
Open site
@@ -24,7 +25,7 @@ export function BookmarkCard({ resource }: CardViewProps): JSX.Element {
2425
<Markdown maxLength={1000} renderGFM text={preview} />
2526
</MarkdownWrapper>
2627
)}
27-
</>
28+
</Column>
2829
);
2930
}
3031

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { useArray, useString, core, collections } from '@tomic/react';
2-
import { useState } from 'react';
2+
import { FC, PropsWithChildren, useState } from 'react';
33

44
import Markdown from '../../components/datatypes/Markdown';
55
import { CardInsideFull, CardRow } from '../../components/Card';
66
import { ResourceInline } from '../ResourceInline';
77
import { CardViewProps } from './CardViewProps';
88
import { Button } from '../../components/Button';
99
import { ResourceCardTitle } from './ResourceCardTitle';
10+
import { Column } from '../../components/Row';
11+
import { styled } from 'styled-components';
1012

1113
const MAX_COUNT = 5;
1214

@@ -27,31 +29,43 @@ function CollectionCard({ resource, small }: CardViewProps): JSX.Element {
2729
}
2830

2931
return (
30-
<>
32+
<Column gap='0.5rem'>
3133
<ResourceCardTitle resource={resource} />
3234
{description && <Markdown text={description} />}
33-
{!small && (
34-
<CardInsideFull>
35-
{subjects.map(member => {
36-
return (
37-
<CardRow key={member}>
38-
<ResourceInline subject={member} />
35+
<Show show={!small}>
36+
{subjects.length === 0 ? (
37+
<Empty>No resources</Empty>
38+
) : (
39+
<CardInsideFull>
40+
{subjects.map(member => {
41+
return (
42+
<CardRow key={member}>
43+
<ResourceInline subject={member} />
44+
</CardRow>
45+
);
46+
})}
47+
{tooMany && (
48+
<CardRow>
49+
<Button clean onClick={() => setShowMore(!showAll)}>
50+
{showAll
51+
? 'show less'
52+
: `show ${members.length - MAX_COUNT} more`}
53+
</Button>
3954
</CardRow>
40-
);
41-
})}
42-
{tooMany && (
43-
<CardRow>
44-
<Button clean onClick={() => setShowMore(!showAll)}>
45-
{showAll
46-
? 'show less'
47-
: `show ${members.length - MAX_COUNT} more`}
48-
</Button>
49-
</CardRow>
50-
)}
51-
</CardInsideFull>
52-
)}
53-
</>
55+
)}
56+
</CardInsideFull>
57+
)}
58+
</Show>
59+
</Column>
5460
);
5561
}
5662

63+
const Show: FC<PropsWithChildren<{ show: boolean }>> = ({ show, children }) => {
64+
return show ? children : null;
65+
};
66+
67+
const Empty = styled.span`
68+
color: ${({ theme }) => theme.colors.textLight};
69+
`;
70+
5771
export default CollectionCard;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { urls, useResource, useString } from '@tomic/react';
33
import Markdown from '../../components/datatypes/Markdown';
44
import { CardViewProps } from './CardViewProps';
55
import { ResourceCardTitle } from './ResourceCardTitle';
6+
import { Column } from '../../components/Row';
67

78
export function ElementCard({ resource }: CardViewProps): JSX.Element {
89
const [documentSubject] = useString(resource, urls.properties.parent);
@@ -11,9 +12,9 @@ export function ElementCard({ resource }: CardViewProps): JSX.Element {
1112
const [text] = useString(resource, urls.properties.description);
1213

1314
return (
14-
<>
15+
<Column gap='0.5rem'>
1516
<ResourceCardTitle resource={document} />
1617
<Markdown text={text ?? ''} />
17-
</>
18+
</Column>
1819
);
1920
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
server,
99
dataBrowser,
1010
collections,
11+
useArray,
1112
} from '@tomic/react';
1213
import AllProps from '../../components/AllProps';
1314
import { AtomicLink } from '../../components/AtomicLink';
@@ -24,6 +25,7 @@ import { ElementCard } from './ElementCard';
2425
import { ArticleCard } from '../Article';
2526
import { styled } from 'styled-components';
2627
import { ResourceCardTitle } from './ResourceCardTitle';
28+
import { Column } from '../../components/Row';
2729

2830
interface ResourceCardProps extends CardViewPropsBase {
2931
/** The subject URL - the identifier of the resource. */
@@ -117,9 +119,14 @@ export function ResourceCardDefault({
117119
resource,
118120
small,
119121
}: CardViewProps): JSX.Element {
122+
const [isA] = useArray(resource, core.properties.isA);
123+
const isAResource = useResource(isA[0]);
124+
120125
return (
121-
<>
122-
<ResourceCardTitle resource={resource} />
126+
<Column gap='0.5rem'>
127+
<ResourceCardTitle resource={resource}>
128+
<ClassName>{isAResource.title}</ClassName>
129+
</ResourceCardTitle>
123130
<DescriptionWrapper>
124131
<ValueForm
125132
resource={resource}
@@ -134,7 +141,7 @@ export function ResourceCardDefault({
134141
editable
135142
/>
136143
)}
137-
</>
144+
</Column>
138145
);
139146
}
140147

@@ -144,3 +151,7 @@ const DescriptionWrapper = styled.div`
144151
max-height: 10rem;
145152
overflow: hidden;
146153
`;
154+
155+
const ClassName = styled.span`
156+
margin-left: auto;
157+
`;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const TitleRow = styled(Row)`
3939
max-width: 100%;
4040
height: 2rem;
4141
overflow: hidden;
42-
margin-bottom: ${({ theme }) => theme.margin}rem;
4342
color: ${({ theme }) => theme.colors.textLight};
4443
4544
svg {

browser/data-browser/src/views/File/FileCard.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useMemo } from 'react';
2+
import { AtomicLink } from '../../components/AtomicLink';
13
import { Row } from '../../components/Row';
24
import { useFileInfo } from '../../hooks/useFile';
35
import { CardViewProps } from '../Card/CardViewProps';
@@ -7,6 +9,23 @@ import { DownloadIconButton } from './DownloadButton';
79
import { FilePreview } from './FilePreview';
810

911
function FileCard(props: CardViewProps): JSX.Element {
12+
const FileError = useMemo(() => {
13+
const Temp = () => {
14+
return (
15+
<>
16+
<AtomicLink subject={props.resource.getSubject()}>
17+
{props.resource.title}
18+
</AtomicLink>
19+
<div>Can not show file due to invalid data.</div>
20+
</>
21+
);
22+
};
23+
24+
Temp.displayName = 'FileError';
25+
26+
return Temp;
27+
}, [props.resource.getSubject(), props.resource.title]);
28+
1029
return (
1130
<ErrorBoundary FallBackComponent={FileError}>
1231
<FileCardInner {...props} />
@@ -16,10 +35,6 @@ function FileCard(props: CardViewProps): JSX.Element {
1635

1736
export default FileCard;
1837

19-
const FileError = () => {
20-
return <div>Can not show file due to invalid data.</div>;
21-
};
22-
2338
function FileCardInner({ resource }: CardViewProps): JSX.Element {
2439
const { downloadFile, bytes } = useFileInfo(resource);
2540

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
const supportedApplicationFormats = new Set([
2+
'application/json',
3+
'application/ld+json',
4+
'application/json-ad',
5+
'application/x-httpd-php',
6+
'application/xhtml+xml',
7+
'application/xml',
8+
'application/x-sh',
9+
]);
10+
111
export const isTextFile = (mimeType: string): boolean =>
2-
mimeType !== 'application/pdf' &&
3-
(mimeType?.startsWith('text/') || mimeType?.startsWith('application/'));
12+
mimeType?.startsWith('text/') || supportedApplicationFormats.has(mimeType);

0 commit comments

Comments
 (0)