Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design2
/
2015104215
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
jaehyuk-jang
2021-06-11 01:10:46 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4fb59c21ec6e441afa60029f947fc788e2608910
4fb59c21
1 parent
a994f66a
Add common shared func
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
project/packages/web/src/shared/functions.ts
project/packages/web/src/shared/functions.ts
0 → 100644
View file @
4fb59c2
import
moment
from
'moment'
;
import
{
useWindowSize
}
from
'@src/hooks'
;
export
const
getMaxLengthByWidth
=
(
width
:
number
)
=>
{
if
(
width
>
590
)
return
30
;
if
(
width
>
474
)
return
20
;
else
return
13
;
};
export
const
sliceTextByLength
=
(
text
:
string
,
length
:
number
)
=>
text
.
length
>
length
?
text
.
substr
(
0
,
length
)
+
'...'
:
text
;
export
const
makeArticleURLWithNumber
=
(
name
:
string
,
id
:
number
)
=>
{
return
`
${
window
.
location
.
origin
}
/
${
name
}
/article?num=
${
id
}
`
;
};
export
const
makeDateForDayOrTime
=
(
date
)
=>
moment
().
diff
(
moment
(
date
),
'days'
)
>
1
?
moment
(
date
).
format
(
'YY.MM.DD'
)
:
moment
(
date
).
format
(
'HH:mm:ss'
);
export
const
makeCategoryTableBody
=
(
list
)
=>
{
const
[
width
]
=
useWindowSize
();
const
newData
=
list
.
map
(({
title
,
id
,
created_date
,
...
rest
})
=>
{
const
textMaxLength
=
getMaxLengthByWidth
(
width
);
const
newTitle
=
sliceTextByLength
(
title
,
textMaxLength
);
const
createdDate
=
makeDateForDayOrTime
(
created_date
);
return
{
...
rest
,
id
,
key
:
String
(
id
),
title
:
newTitle
,
created_date
:
createdDate
,
};
});
newData
.
sort
((
a
,
b
)
=>
Number
(
b
.
id
)
-
Number
(
a
.
id
));
return
newData
;
};
Please
register
or
login
to post a comment