'use client' import React, { useState } from 'react'; import { ITag } from '../lib/tags'; import Link from 'next/link'; import slugify from 'slugify'; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faFilter } from "@fortawesome/free-solid-svg-icons"; interface ISortableTagsProps { tags: ITag[]; } export default function SortableTags({ tags }: ISortableTagsProps) { const [filterText, setFilterText] = useState(''); const [sortOption, setSortOption] = useState('Sort'); const filteredTags = tags.filter((tag: ITag) => tag.attributes.name.toLowerCase().includes(filterText.toLowerCase()) ); const sortedTags = [...filteredTags].sort((a, b) => { if (sortOption === 'Alphabetical') { return a.attributes.name.localeCompare(b.attributes.name); } else if (sortOption === 'Frequency') { return b.attributes.count - a.attributes.count; } return 0; }); return ( <>
setFilterText(e.target.value)} />
{sortedTags.map((tag: ITag) => ( {tag.attributes.name} ({tag.attributes.count}) ))}
); }