add see more/less toggle on prompt cards for long content

This commit is contained in:
CREDO23 2026-03-30 20:31:19 +02:00
parent bcb202dfe1
commit a73bab89d9
2 changed files with 30 additions and 6 deletions

View file

@ -12,6 +12,7 @@ export function CommunityPromptsContent() {
const [prompts, setPrompts] = useState<PublicPromptRead[]>([]); const [prompts, setPrompts] = useState<PublicPromptRead[]>([]);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [copyingId, setCopyingId] = useState<number | null>(null); const [copyingId, setCopyingId] = useState<number | null>(null);
const [expandedId, setExpandedId] = useState<number | null>(null);
useEffect(() => { useEffect(() => {
promptsApiService promptsApiService
@ -73,12 +74,23 @@ export function CommunityPromptsContent() {
<span className="rounded-full border px-2 py-0.5 text-[10px] text-muted-foreground"> <span className="rounded-full border px-2 py-0.5 text-[10px] text-muted-foreground">
{prompt.mode} {prompt.mode}
</span> </span>
{prompt.author_name && (
<span className="text-[11px] text-muted-foreground/60">
by {prompt.author_name}
</span>
)}
</div> </div>
<p className="mt-1 text-xs text-muted-foreground line-clamp-2">{prompt.prompt}</p> <p className={`mt-1 text-xs text-muted-foreground ${expandedId === prompt.id ? "whitespace-pre-wrap" : "line-clamp-2"}`}>
{prompt.author_name && ( {prompt.prompt}
<p className="mt-1.5 text-[11px] text-muted-foreground/60"> </p>
by {prompt.author_name} {prompt.prompt.length > 100 && (
</p> <button
type="button"
onClick={() => setExpandedId(expandedId === prompt.id ? null : prompt.id)}
className="mt-1 text-[11px] text-primary hover:underline cursor-pointer"
>
{expandedId === prompt.id ? "See less" : "See more"}
</button>
)} )}
</div> </div>
<Button <Button

View file

@ -27,6 +27,7 @@ export function PromptsContent() {
const [editingId, setEditingId] = useState<number | null>(null); const [editingId, setEditingId] = useState<number | null>(null);
const [formData, setFormData] = useState<PromptFormData>(EMPTY_FORM); const [formData, setFormData] = useState<PromptFormData>(EMPTY_FORM);
const [isSaving, setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
const [expandedId, setExpandedId] = useState<number | null>(null);
useEffect(() => { useEffect(() => {
promptsApiService promptsApiService
@ -227,7 +228,18 @@ export function PromptsContent() {
</span> </span>
)} )}
</div> </div>
<p className="mt-1 text-xs text-muted-foreground line-clamp-2">{prompt.prompt}</p> <p className={`mt-1 text-xs text-muted-foreground ${expandedId === prompt.id ? "whitespace-pre-wrap" : "line-clamp-2"}`}>
{prompt.prompt}
</p>
{prompt.prompt.length > 100 && (
<button
type="button"
onClick={() => setExpandedId(expandedId === prompt.id ? null : prompt.id)}
className="mt-1 text-[11px] text-primary hover:underline cursor-pointer"
>
{expandedId === prompt.id ? "See less" : "See more"}
</button>
)}
</div> </div>
<div className="hidden group-hover:flex items-center gap-1 shrink-0"> <div className="hidden group-hover:flex items-center gap-1 shrink-0">
<button <button