Skip to content

Commit 43da315

Browse files
committed
move truncateDescription to helpers
1 parent c430d32 commit 43da315

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pages/browse/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
configureErrors,
1313
configureServices,
1414
useFilteredWares,
15+
truncateDescription,
1516
} from '../../utils'
1617

1718
const Browse = ({ session }) => {
@@ -48,12 +49,12 @@ const Browse = ({ session }) => {
4849
)
4950
}
5051

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-
}
52+
// const truncateDescription = (desc = '', maxLength, isOpen) => {
53+
// if (desc.length <= maxLength || isOpen) return { truncated: desc, cutOffIndex: desc.length }
54+
// const lastSpaceIndex = desc.substring(0, maxLength).lastIndexOf(' ')
55+
// const ellipsis = isOpen ? '' : '...'
56+
// return { truncated: desc.slice(0, lastSpaceIndex) + ellipsis, cutOffIndex: lastSpaceIndex }
57+
// }
5758

5859
return (
5960
<div className='container'>

utils/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,10 @@ export const formatBytes = (bytes, decimals = 2) => {
8282

8383
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
8484
}
85+
86+
export const truncateDescription = (desc = '', maxLength, isOpen) => {
87+
if (desc.length <= maxLength || isOpen) return { truncated: desc, cutOffIndex: desc.length }
88+
const lastSpaceIndex = desc.substring(0, maxLength).lastIndexOf(' ')
89+
const ellipsis = isOpen ? '' : '...'
90+
return { truncated: desc.slice(0, lastSpaceIndex) + ellipsis, cutOffIndex: lastSpaceIndex }
91+
}

0 commit comments

Comments
 (0)