import React from 'react'; import { colours } from '@times-components/ts-styleguide'; import { IconStar } from '@times-components/icons'; import { useFetch } from '../../helpers/fetch/FetchProvider'; import { IconContainer, LoadingIcon, SaveStarText, SaveStarButton } from './styles'; export type ArticleBookmark = { isBookmarked: boolean; }; const getText = (isSaved: boolean) => (isSaved ? 'Saved' : 'Save'); const getIconTitle = (isSaved: boolean) => isSaved ? 'Remove from My Articles' : 'Save to My Articles'; const getIconFillColour = (isSaved: boolean) => isSaved ? colours.functional.action : colours.functional.white; export const SaveStarUI: React.FC<{ articleId: string; onToggleSave: (id: string, isSaved: boolean) => void; }> = ({ articleId, onToggleSave }) => { const { loading, error, data } = useFetch(); if (loading) { return ( <> {getText(false)} ); } if (error || !data) { return null; } return ( <> {getText(data.isBookmarked)} onToggleSave(articleId, data.isBookmarked)} > ); };