-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add collection tag on report page
Signed-off-by: laixingyou <[email protected]>
- Loading branch information
1 parent
91efe56
commit 40a808e
Showing
8 changed files
with
90 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'next-i18next'; | ||
import { useRouter } from 'next/navigation'; | ||
import Tooltip from '@common/components/Tooltip'; | ||
import { getSecondIdentName } from '@common/collectionsI18n'; | ||
import cls from 'classnames'; | ||
|
||
const CollectionTag = ({ | ||
collections, | ||
className, | ||
}: { | ||
collections: string[]; | ||
className: string; | ||
}) => { | ||
const { t, i18n } = useTranslation(); | ||
const router = useRouter(); | ||
const first = collections?.[0]; | ||
|
||
let restCollections: string[] = []; | ||
if (collections?.length > 1) { | ||
restCollections = collections?.slice(1).map((item) => { | ||
return getSecondIdentName(item, i18n.language); | ||
}); | ||
} | ||
|
||
return ( | ||
<div | ||
className={cls( | ||
'text-secondary flex cursor-pointer items-center text-xs', | ||
className | ||
)} | ||
> | ||
{first ? ( | ||
<> | ||
<div | ||
className="bg-smoke rounded px-2 py-1.5" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
router.push(`/collection/${first}`); | ||
}} | ||
> | ||
{getSecondIdentName(first, i18n.language)} | ||
</div> | ||
{collections?.length > 1 ? ( | ||
<Tooltip | ||
title={ | ||
<div className="p-2 text-white"> | ||
{restCollections?.join(', ')} | ||
</div> | ||
} | ||
> | ||
<div className="ml-1">+{collections.length - 1}</div> | ||
</Tooltip> | ||
) : null} | ||
</> | ||
) : null} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CollectionTag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.