Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix abstract format issue on UI #211

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/list/listItem/subitem/ExpandableTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button, Grid, Typography } from "@mui/material";
import {
decodeHtmlEntities,
truncateText,
enrichHTML,
} from "../../../../utils/StringUtils";

interface ExpandableTextAreaProps {
Expand All @@ -24,19 +25,20 @@ const ExpandableTextArea: React.FC<ExpandableTextAreaProps> = ({
showMoreStr = "Show More",
}) => {
const decodedText = decodeHtmlEntities(text);
const truncatedText = truncateText(decodedText, truncateCount);
const doesNeedTruncation = decodedText.length > truncateCount;

const [isExpanded, setIsExpanded] = useState(false);

const onButtonClick = useCallback(() => {
setIsExpanded((prev) => !prev);
}, []);

return (
<TextAreaBaseGrid>
<Grid item md={12}>
<Typography
variant="detailContent"
whiteSpace="pre-wrap"
sx={{
textAlign: "left",
...(isClickable && {
Expand All @@ -48,7 +50,7 @@ const ExpandableTextArea: React.FC<ExpandableTextAreaProps> = ({
}}
onClick={onClick}
>
{isExpanded ? decodedText : truncatedText}
{isExpanded ? decodedText : truncateText(decodedText, truncateCount)}
</Typography>
</Grid>
<Grid item md={12} display="flex" justifyContent="flex-end">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import Layers from "../../../../components/map/mapbox/layers/Layers";
import { StaticLayersDef } from "../../../../components/map/mapbox/layers/StaticLayer";
import { MapboxWorldLayersDef } from "../../../../components/map/mapbox/layers/MapboxWorldLayer";
import useScrollToSection from "../../../../hooks/useScrollToSection";
import { decodeHtmlEntities } from "../../../../utils/StringUtils";
import ExpandableTextArea from "../../../../components/list/listItem/subitem/ExpandableTextArea";
import DetailClusterLayer from "../../../../components/map/mapbox/layers/DetailClusterLayer";

Expand Down Expand Up @@ -156,7 +155,7 @@ const AbstractAndDownloadPanel: FC = () => {
<Grid item xs={12}>
<Stack direction="column">
<ExpandableTextArea
text={decodeHtmlEntities(abstract)}
text={abstract}
showMoreStr={"Show All"}
truncateCount={TRUNCATE_COUNT}
/>
Expand Down
13 changes: 13 additions & 0 deletions src/utils/StringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// e.g capitalize, concatenate, ...

import { decode } from "he";
import React from "react";

/**
* Capitalizes the first letter of a given string.
Expand Down Expand Up @@ -46,3 +47,15 @@ export const decodeHtmlEntities = (str: string): string => {
return str;
}
};
// TODO: Keep it for now, we want to enhance the url later with http
export const enrichHTML = (text: string): string => {
// Regular expression to match URLs with http:// or https://
const urlPattern = /\bhttps?:\/\/[^\s/$.?#].[^\s]*\b/g;

// Replace URLs in the text with anchor tags
const h = text.replace(urlPattern, (url) => {
return `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`;
});

return h.replace(/\n/g, "<br>");
};
Loading