feat: Add link parsing functionality to notes in ProjectViewPage and TaskCommentsModal

This commit is contained in:
2025-10-02 11:36:36 +02:00
parent 31736ccc78
commit 79238dd643
3 changed files with 194 additions and 15 deletions

View File

@@ -28,6 +28,41 @@ export default function ProjectViewPage() {
const [loading, setLoading] = useState(true);
const [uploadedFiles, setUploadedFiles] = useState([]);
// Helper function to parse note text with links
const parseNoteText = (text) => {
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
const parts = [];
let lastIndex = 0;
let match;
while ((match = linkRegex.exec(text)) !== null) {
// Add text before the link
if (match.index > lastIndex) {
parts.push(text.slice(lastIndex, match.index));
}
// Add the link
parts.push(
<a
key={match.index}
href={match[2]}
className="text-blue-600 hover:text-blue-800 underline"
target="_blank"
rel="noopener noreferrer"
>
{match[1]}
</a>
);
lastIndex = match.index + match[0].length;
}
// Add remaining text
if (lastIndex < text.length) {
parts.push(text.slice(lastIndex));
}
return parts.length > 0 ? parts : text;
};
// Helper function to add a new note to the list
const addNote = (newNote) => {
setNotes(prevNotes => [newNote, ...prevNotes]);
@@ -758,7 +793,9 @@ export default function ProjectViewPage() {
</button>
)}
</div>
<p className="text-gray-900 leading-relaxed">{n.note}</p>
<div className="text-gray-900 leading-relaxed">
{parseNoteText(n.note)}
</div>
</div>
))}
</div>