Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
300566c5
authored
Apr 03, 2024
by
Calcium-Ion
Committed by
GitHub
Apr 03, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #176 from QuentinHsu/perf-helpers-renderGroup
refactor(helpers): renderGroup function
parents
63597081
f2f5b73c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
29 deletions
+27
-29
web/src/helpers/render.js
+27
-29
No files found.
web/src/helpers/render.js
View file @
300566c5
...
...
@@ -8,39 +8,37 @@ export function renderText(text, limit) {
return
text
;
}
/**
* Render group tags based on the input group string
* @param {string} group - The input group string
* @returns {JSX.Element} - The rendered group tags
*/
export
function
renderGroup
(
group
)
{
if
(
group
===
''
)
{
return
<
Tag
size
=
'large'
>
default
<
/Tag>
;
return
<
Tag
size
=
'large'
key
=
'default'
>
default
<
/Tag>
;
}
let
groups
=
group
.
split
(
','
);
groups
.
sort
();
const
tagColors
=
{
'vip'
:
'yellow'
,
'pro'
:
'yellow'
,
'svip'
:
'red'
,
'premium'
:
'red'
};
const
groups
=
group
.
split
(
','
).
sort
();
return
(
<>
{
groups
.
map
((
group
)
=>
{
if
(
group
===
'vip'
||
group
===
'pro'
)
{
return
(
<
Tag
size
=
'large'
color
=
'yellow'
>
{
group
}
<
/Tag
>
);
}
else
if
(
group
===
'svip'
||
group
===
'premium'
)
{
return
(
<
Tag
size
=
'large'
color
=
'red'
>
{
group
}
<
/Tag
>
);
}
if
(
group
===
'default'
)
{
return
<
Tag
size
=
'large'
>
{
group
}
<
/Tag>
;
}
else
{
return
(
<
Tag
size
=
'large'
color
=
{
stringToColor
(
group
)}
>
{
group
}
<
/Tag
>
);
}
})}
<
/
>
<
span
key
=
{
group
}
>
{
groups
.
map
((
group
)
=>
(
<
Tag
size
=
'large'
color
=
{
tagColors
[
group
]
||
stringToColor
(
group
)}
key
=
{
group
}
>
{
group
}
<
/Tag
>
))}
<
/span
>
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment