Skip to content

Commit

Permalink
Made links in descriptions clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-dalby committed Nov 13, 2024
1 parent 8d34998 commit 4b3a5a7
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 51 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@monaco-editor/react": "^4.6.0",
"date-fns": "^4.1.0",
"framer-motion": "^11.11.9",
"linkify-react": "^4.1.3",
"lucide-react": "^0.452.0",
"monaco-editor": "^0.52.0",
"parse-duration": "^1.1.0",
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/snippets/list/SnippetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ConfirmationModal } from '../../common/modals/ConfirmationModal';
import { Snippet } from '../../../types/snippets';
import CategoryList from '../../categories/CategoryList';
import { PreviewCodeBlock } from '../../editor/PreviewCodeBlock';
import Linkify from 'linkify-react';
import { linkifyOptions } from '../../../constants/linkify';

interface SnippetCardProps {
snippet: Snippet;
Expand Down Expand Up @@ -110,7 +112,9 @@ export const SnippetCard: React.FC<SnippetCardProps> = ({

{!compactView && (
<p className="text-sm text-gray-300 mb-3 line-clamp-1">
{snippet.description || 'No description available'}
<Linkify options={linkifyOptions} >
{snippet.description || 'No description available'}
</Linkify>
</p>
)}

Expand Down
30 changes: 19 additions & 11 deletions client/src/components/snippets/view/FullCodeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import { Snippet } from '../../../types/snippets';
import CategoryList from '../../categories/CategoryList';
import { getLanguageLabel } from '../../../utils/language/languageUtils';
import { FullCodeBlock } from '../../editor/FullCodeBlock';
import Linkify from 'linkify-react';
import { linkifyOptions } from '../../../constants/linkify';

interface FullCodeViewProps {
showTitle?: boolean;
snippet: Snippet;
onCategoryClick?: (category: string) => void;
showLineNumbers?: boolean;
className?: string;
}

export const FullCodeView: React.FC<FullCodeViewProps> = ({
showTitle = true,
snippet,
onCategoryClick,
showLineNumbers = true,
Expand All @@ -27,8 +31,14 @@ export const FullCodeView: React.FC<FullCodeViewProps> = ({
return (
<div className={className}>
<div className="mb-8">
<h1 className="text-3xl font-bold mb-4">{snippet.title}</h1>
<p className="text-gray-300 mb-4">{snippet.description}</p>
{showTitle && (
<h1 className="text-3xl font-bold mb-4">{snippet.title}</h1>
)}
<p className="text-gray-300 mb-4">
<Linkify options={linkifyOptions}>
{snippet.description || 'No description available'}
</Linkify>
</p>

<div className="flex items-center gap-4 text-sm text-gray-400">
<div className="flex items-center gap-1">
Expand All @@ -37,15 +47,13 @@ export const FullCodeView: React.FC<FullCodeViewProps> = ({
</div>
</div>

{snippet.categories?.length > 0 && (
<CategoryList
categories={snippet.categories}
onCategoryClick={handleCategoryClick}
className="mt-4"
variant="clickable"
showAll={true}
/>
)}
<CategoryList
categories={snippet.categories}
onCategoryClick={handleCategoryClick}
className="mt-4"
variant="clickable"
showAll={true}
/>
</div>

<div className="space-y-6">
Expand Down
45 changes: 6 additions & 39 deletions client/src/components/snippets/view/SnippetModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React from "react";
import { FileCode } from "lucide-react";
import { Snippet } from "../../../types/snippets";
import Modal from "../../common/modals/Modal";
import CategoryList from "../../categories/CategoryList";
import { getLanguageLabel } from "../../../utils/language/languageUtils";
import { FullCodeBlock } from "../../editor/FullCodeBlock";
import { FullCodeView } from "./FullCodeView";

export interface SnippetModalProps {
snippet: Snippet | null;
Expand Down Expand Up @@ -36,42 +33,12 @@ const SnippetModal: React.FC<SnippetModalProps> = ({
<h2 className="text-2xl font-bold text-gray-100">{snippet.title}</h2>
}
>
<p className="text-sm text-gray-300 mb-4 break-words">
{snippet.description}
</p>

<CategoryList
categories={snippet.categories || []}
onCategoryClick={handleCategoryClick}
className="mb-6"
variant="clickable"
showAll={true}
<FullCodeView
showTitle={false}
snippet={snippet}
showLineNumbers={showLineNumbers}
onCategoryClick={() => handleCategoryClick}
/>

<div className="space-y-6">
{snippet.fragments.map((fragment, index) => (
<div key={index} className="bg-gray-700 rounded-lg overflow-hidden">
<div className="flex items-center justify-between px-4 pt-4">
<div className="flex items-center gap-2">
<FileCode size={16} className="text-gray-400" />
<span className="text-sm font-medium text-gray-200">
{fragment.file_name}
</span>
</div>
<span className="text-sm text-gray-400">
{getLanguageLabel(fragment.language)}
</span>
</div>
<div className="p-4">
<FullCodeBlock
code={fragment.code}
language={fragment.language}
showLineNumbers={showLineNumbers}
/>
</div>
</div>
))}
</div>
</Modal>
);
};
Expand Down
9 changes: 9 additions & 0 deletions client/src/constants/linkify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const linkifyOptions = {
defaultProtocol: 'https',
target: '_blank',
rel: 'noopener noreferrer',
className: 'text-blue-400 hover:text-blue-300 transition-colors duration-200 underline decoration-blue-400/50 hover:decoration-blue-300 cursor-pointer',
validate: {
url: (_: any) => true
}
};
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b3a5a7

Please sign in to comment.