import apiFetch from '@wordpress/api-fetch'; import { __, sprintf } from '@wordpress/i18n'; import React from 'react'; import { useQuery } from 'react-query'; import { ChangelogsMap } from '../types'; import ChangelogSkeleton from './ChangelogSkeleton'; type ChangelogTag = | 'Updated' | 'Update' | 'Fix' | 'Added' | 'Add' | 'Feature' | 'Enhancement' | 'Tweak'; const Changelog: React.FC = () => { const changelogQuery = useQuery(['changelog'], () => apiFetch({ path: 'colormag/v1/changelog', }), ); const getClassNames = (tag: ChangelogTag) => { const baseClass = 'sticky top-0 font-normal z-10 w-fit px-[8px] py-[4px] rounded-[3px] font-semibold'; const tagClasses = { Updated: 'bg-[#c6f6d5] text-[#22543d]', Update: 'bg-[#c6f6d5] text-[#22543d]', Fix: 'bg-[#e8eefd] text-[#0b2c75]', Added: 'bg-[#fed7e2] text-[#702459]', Add: 'bg-[#fed7e2] text-[#702459]', Feature: 'bg-[#fed7e2] text-[#702459]', Enhancement: 'bg-[#b2f5ea] text-[#234e52]', Tweak: 'bg-[#e9d8fd] text-[#44337a]', } as const; return `${baseClass} ${tagClasses[tag]}`; }; const strokeColor = (tag: ChangelogTag) => { const tagClasses = { Updated: '#22543d', Update: '#22543d', Fix: '#0b2c75', Added: '#702459', Add: '#702459', Feature: '#702459', Enhancement: '#234e52', Tweak: '#44337a', } as const; return tagClasses[tag]; }; if (changelogQuery.isLoading) { return ; } return ( <> {changelogQuery.data?.map((changelog) => (

{sprintf(__('Version %s'), changelog.version)}

{changelog.date}

{Object.entries(changelog.changes).map(([tag, changes], i) => (
{tag}
{changes.map((change, j) => ( {change} ))}
))}
))} ); }; export default Changelog;