Skip to content

Commit d669a7c

Browse files
committed
get markdown working
1 parent fe10ae8 commit d669a7c

File tree

4 files changed

+675
-17
lines changed

4 files changed

+675
-17
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"next-auth": "^4.20.1",
3434
"react": "18.2.0",
3535
"react-dom": "18.2.0",
36+
"react-markdown": "^9.0.1",
3637
"sass": "^1.56.1",
3738
"start-server-and-test": "^2.0.3",
3839
"swr": "^1.3.0"

pages/browse/index.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Notice,
77
SearchBar,
88
} from '@scientist-softserv/webstore-component-library'
9+
import Markdown from 'react-markdown'
910
import {
1011
buttonBg,
1112
configureErrors,
@@ -18,6 +19,7 @@ const Browse = ({ session }) => {
1819
const [query, setQuery] = useState('')
1920
const existingQuery = router.query.q
2021
const accessToken = session?.accessToken
22+
const [open, setOpen] = useState(false)
2123

2224
useEffect(() => {
2325
if (existingQuery) setQuery(existingQuery)
@@ -46,6 +48,13 @@ const Browse = ({ session }) => {
4648
)
4749
}
4850

51+
const truncateDescription = (desc = '', maxLength, isOpen) => {
52+
if (desc.length <= maxLength || isOpen) return { truncated: desc, cutOffIndex: desc.length };
53+
const lastSpaceIndex = desc.substring(0, maxLength).lastIndexOf(' ');
54+
const ellipsis = isOpen ? '' : '...';
55+
return { truncated: desc.slice(0, lastSpaceIndex) + ellipsis, cutOffIndex: lastSpaceIndex };
56+
}
57+
4958
return (
5059
<div className='container'>
5160
<SearchBar onSubmit={handleOnSubmit} initialValue={existingQuery} />
@@ -60,19 +69,32 @@ const Browse = ({ session }) => {
6069
<>
6170
{(services.length > 0) ? (
6271
<>
63-
{services.map(service => (
64-
<Item
65-
key={service.id}
66-
item={service}
67-
withButtonLink={true}
68-
buttonLink={service.href}
69-
orientation='horizontal'
70-
buttonProps={{
71-
backgroundColor: buttonBg,
72-
label: 'Request this item',
73-
}}
74-
/>
75-
))}
72+
{services.map(service => {
73+
const { truncated, cutOffIndex } = truncateDescription(service?.description, 300, open)
74+
return (
75+
<Item
76+
key={service.id}
77+
markdownDescriptionTruncated={(
78+
<Markdown>
79+
{truncated}
80+
</Markdown>
81+
)}
82+
markdownDescriptionExtended={(
83+
<Markdown>
84+
{service?.description?.slice(cutOffIndex).trimStart()}
85+
</Markdown>
86+
)}
87+
item={service}
88+
withButtonLink={true}
89+
buttonLink={service.href}
90+
orientation='horizontal'
91+
buttonProps={{
92+
backgroundColor: buttonBg,
93+
label: 'Request this item',
94+
}}
95+
/>
96+
)
97+
})}
7698
</>
7799
) : (
78100
<p data-cy='no-results'>

utils/api/configurations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const configureServices = ({ data, path }) => {
1616

1717
return {
1818
description: ware.description === '' ? ware.snippet : ware.description,
19+
snippet: ware.snippet,
1920
id: ware.id,
2021
img,
2122
name: ware.name,

0 commit comments

Comments
 (0)