-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
023816b
commit 9bf969a
Showing
6 changed files
with
162 additions
and
3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions
116
web-app/src/components/site/index-details/ArticleItem/index.tsx
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,116 @@ | ||
import Freizeit from "@/fonts/loader"; | ||
import { shortStr } from "@/utils/helper"; | ||
import Button from "components/base/Button"; | ||
import IconContextMenu from "components/base/Icon/IconContextMenu"; | ||
import Text from "components/base/Text"; | ||
import Col from "components/layout/base/Grid/Col"; | ||
import FlexRow from "components/layout/base/Grid/FlexRow"; | ||
import IndexDetailItemPopup from "components/site/popup/IndexDetailItemPopup"; | ||
import { useRole } from "hooks/useRole"; | ||
import moment from "moment"; | ||
import React from "react"; | ||
import sanitize from "sanitize-html"; | ||
import { ArticleIndexNodeItem, DefaultIndexNodeItem } from "types/entity"; | ||
|
||
export interface ArticleItemProps { | ||
item: ArticleIndexNodeItem; | ||
onChange?(val: DefaultIndexNodeItem[]): void; | ||
search?: boolean; | ||
handleRemove?(): void; | ||
} | ||
|
||
const ArticleItem: React.FC<ArticleItemProps> = ({ | ||
item, | ||
search = false, | ||
handleRemove, | ||
}) => { | ||
const { node } = item; | ||
|
||
const { isCreator } = useRole(); | ||
|
||
return ( | ||
<div className="index-detail-list-item-wrapper"> | ||
<FlexRow className="index-detail-list-item py-3"> | ||
<Col xs={12}> | ||
<FlexRow wrap={false} style={{ height: "24px" }}> | ||
<Col className="idxflex-grow-1"> | ||
<img | ||
className="mt-0 mr-3" | ||
src={"/images/article.svg"} | ||
alt="favicon" | ||
width={16} | ||
height={16} | ||
onError={(e: React.SyntheticEvent<HTMLImageElement, Event>) => { | ||
const target = e.target as HTMLImageElement; | ||
target.onerror = null; // Prevents infinite loop in case fallback image also fails | ||
target.src = "/images/article.svg"; | ||
}} | ||
style={{ | ||
verticalAlign: "middle", | ||
}} | ||
/> | ||
<a href={node.url} target="_blank"> | ||
<Text | ||
className={Freizeit.className} | ||
style={{ | ||
fontSize: "16px", | ||
}} | ||
fontWeight={700} | ||
dangerouslySetInnerHTML={{ | ||
__html: sanitize(shortStr(node?.title)), | ||
}} | ||
/> | ||
</a> | ||
</Col> | ||
{!search && isCreator ? ( | ||
<Col className="idxflex-shrink-0 index-detail-list-item-buttons ml-3"> | ||
<FlexRow> | ||
<Col></Col> | ||
<Col> | ||
<IndexDetailItemPopup onDelete={handleRemove}> | ||
<Button size="xs" iconButton theme="clear" borderless> | ||
<IconContextMenu /> | ||
</Button> | ||
</IndexDetailItemPopup> | ||
</Col> | ||
</FlexRow> | ||
</Col> | ||
) : ( | ||
<Col className="idxflex-shrink-0 index-detail-list-item-buttons ml-3"> | ||
<FlexRow> | ||
<Col></Col> | ||
<Col> | ||
<IndexDetailItemPopup onDelete={handleRemove} /> | ||
</Col> | ||
</FlexRow> | ||
</Col> | ||
)} | ||
</FlexRow> | ||
</Col> | ||
<Col xs={12} className="mt-2"> | ||
<Text size="sm" theme="gray5"> | ||
{item.type} | ||
{" • "} | ||
<a | ||
href={node.url} | ||
target="_blank" | ||
style={{ | ||
color: "#475569", | ||
}} | ||
> | ||
{node.url} | ||
</a> | ||
{" • "} | ||
</Text> | ||
|
||
<Text size="sm" theme="gray5"> | ||
{node?.createdAt | ||
? `Published ${moment(new Date(node.createdAt)).fromNow()}` | ||
: ""} | ||
</Text> | ||
</Col> | ||
</FlexRow> | ||
</div> | ||
); | ||
}; | ||
export default ArticleItem; |
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