import * as React from 'react';
import { Issue } from './reportManagerSchema';
import { darkColors, getLabelColors, isLightText, lightColors } from './reportManagerUtils';
import ReactMarkdown from 'react-markdown';
import rehypeRaw from 'rehype-raw';
import remarkGfm from 'remark-gfm';
import { StrCast } from '../../../fields/Types';
import { Doc } from '../../../fields/Doc';
/**
* Mini components to render issues.
*/
interface IssueCardProps {
issue: Issue;
onSelect: () => void;
}
// Component for the issue cards list on the left
export const IssueCard = ({ issue, onSelect }: IssueCardProps) => {
const [textColor, setTextColor] = React.useState('');
const [bgColor, setBgColor] = React.useState('');
const [borderColor, setBorderColor] = React.useState('');
const resetColors = () => {
const darkMode = isLightText(StrCast(Doc.UserDoc().userBackgroundColor));
const colors = darkMode ? darkColors : lightColors;
setTextColor(colors.text);
setBorderColor(colors.border);
setBgColor('transparent');
};
const handlePointerOver = () => {
const darkMode = isLightText(StrCast(Doc.UserDoc().userVariantColor));
setTextColor(darkMode ? darkColors.text : lightColors.text);
setBorderColor(StrCast(Doc.UserDoc().userVariantColor));
setBgColor(StrCast(Doc.UserDoc().userVariantColor));
};
React.useEffect(() => {
resetColors();
}, []);
return (
{issue.labels.map(label => {
const labelString = typeof label === 'string' ? label : label.name ?? '';
const colors = getLabelColors(labelString);
return ;
})}
{issue.title}
);
};
interface IssueViewProps {
issue: Issue;
}
// Detailed issue view that displays on the right
export const IssueView = ({ issue }: IssueViewProps) => {
const [issueBody, setIssueBody] = React.useState('');
// Parses the issue body into a formatted markdown (main functionality is replacing urls with tags)
const parseBody = async (body: string) => {
const imgTagRegex = /
]*\/?>/;
const videoTagRegex = /