@ -17,6 +17,14 @@ import { useToast } from '../../hooks/use-toast';
import { Spinner } from '../ReactIcons/Spinner' ;
import { ChevronDown } from 'lucide-react' ;
const statusColors : Record < ResourceProgressType , string > = {
done : 'bg-green-500' ,
learning : 'bg-yellow-500' ,
pending : 'bg-gray-300' ,
skipped : 'bg-black' ,
removed : '' ,
} ;
type TopicProgressButtonProps = {
topicId : string ;
resourceId : string ;
@ -25,14 +33,32 @@ type TopicProgressButtonProps = {
onClose : ( ) = > void ;
} ;
const statusColors : Record < ResourceProgressType , string > = {
done : 'bg-green-500' ,
learning : 'bg-yellow-500' ,
pending : 'bg-gray-300' ,
skipped : 'bg-black' ,
removed : '' ,
type ProgressDropdownItemProps = {
status : ResourceProgressType ;
shortcutKey : string ;
label : string ;
onClick : ( ) = > void ;
} ;
function ProgressDropdownItem ( props : ProgressDropdownItemProps ) {
const { status , shortcutKey , label , onClick } = props ;
return (
< button
className = "inline-flex justify-between px-3 py-1.5 text-left text-sm text-gray-800 hover:bg-gray-100"
onClick = { onClick }
>
< span >
< span
className = { ` mr-2 inline-block h-2 w-2 rounded-full ${ statusColors [ status ] } ` }
> < / span >
{ label }
< / span >
< span className = "text-xs text-gray-500" > { shortcutKey } < / span >
< / button >
) ;
}
export function TopicProgressButton ( props : TopicProgressButtonProps ) {
const { topicId , resourceId , resourceType , onClose } = props ;
@ -197,95 +223,66 @@ export function TopicProgressButton(props: TopicProgressButtonProps) {
if ( isUpdatingProgress ) {
return (
< button className = "inline-flex cursor-default items-center rounded-md border border-gray-300 b g-white p-1 px-2 text-sm text-black" >
< Spinner className = "h-4 w-4" / >
< button className = "inline-flex cursor-default items-center rounded-md bg-white p-1 px-2 text-sm text-black" >
< Spinner isDualRing = { false } className = "h-4 w-4" / >
< span className = "ml-2" > Updating Status . . < / span >
< / button >
) ;
}
return (
< div className = "relative inline-flex rounded-md border border-gray-300" >
< span className = "inline-flex cursor-default items-center p-1 px-2 text-sm text-black" >
< div className = "relative inline-flex" >
< button
onClick = { ( ) = > setShowChangeStatus ( true ) }
className = "inline-flex cursor-pointer items-center gap-2 rounded-md p-1 px-2 text-sm text-black hover:bg-gray-100"
>
< span className = "flex h-2 w-2" >
< span
className = { ` relative inline-flex h-2 w-2 rounded-full ${ statusColors [ progress ] } ` }
> < / span >
< / span >
< span className = "ml-2 capitalize" >
< span className = "capitalize" >
{ progress === 'learning' ? 'In Progress' : progress }
< / span >
< / span >
< button
className = "inline-flex cursor-pointer items-center rounded-tr-md rounded-br-md border-l border-l-gray-300 bg-gray-100 p-1 px-2 text-sm text-black hover:bg-gray-200"
onClick = { ( ) = > setShowChangeStatus ( true ) }
>
< span className = "mr-0.5" > Update Status < / span >
< ChevronDown className = "h-4 w-4" / >
< / button >
{ showChangeStatus && (
< div
className = "absolute top-full right- 0 mt-1 flex min-w-[160px] flex-col divide-y rounded-md border border-gray-200 bg-white shadow-md [&>button:first-child]:rounded-t-md [&>button:last-child]:rounded-b-md"
className = "absolute top-full left-0 z-50 mt-1 flex min-w-[160px] flex-col divide-y rounded-md border border-gray-200 bg-white shadow-md [&>button:first-child]:rounded-t-md [&>button:last-child]:rounded-b-md"
ref = { changeStatusRef ! }
>
{ allowMarkingDone && (
< button
className = "inline-flex justify-between px-3 py-1.5 text-left text-sm text-gray-800 hover:bg-gray-100"
< ProgressDropdownItem
status = "done"
shortcutKey = "D"
label = "Done"
onClick = { ( ) = > handleUpdateResourceProgress ( 'done' ) }
>
< span >
< span
className = { ` mr-2 inline-block h-2 w-2 rounded-full ${ statusColors [ 'done' ] } ` }
> < / span >
Done
< / span >
< span className = "text-xs text-gray-500" > D < / span >
< / button >
/ >
) }
{ allowMarkingLearning && (
< button
className = "inline-flex justify-between px-3 py-1.5 text-left text-sm text-gray-800 hover:bg-gray-100"
< ProgressDropdownItem
status = "learning"
shortcutKey = "L"
label = "In Progress"
onClick = { ( ) = > handleUpdateResourceProgress ( 'learning' ) }
>
< span >
< span
className = { ` mr-2 inline-block h-2 w-2 rounded-full ${ statusColors [ 'learning' ] } ` }
> < / span >
In Progress
< / span >
< span className = "text-xs text-gray-500" > L < / span >
< / button >
/ >
) }
{ allowMarkingPending && (
< button
className = "inline-flex justify-between px-3 py-1.5 text-left text-sm text-gray-800 hover:bg-gray-100"
< ProgressDropdownItem
status = "pending"
shortcutKey = "R"
label = "Reset"
onClick = { ( ) = > handleUpdateResourceProgress ( 'pending' ) }
>
< span >
< span
className = { ` mr-2 inline-block h-2 w-2 rounded-full ${ statusColors [ 'pending' ] } ` }
> < / span >
Reset
< / span >
< span className = "text-xs text-gray-500" > R < / span >
< / button >
/ >
) }
{ allowMarkingSkipped && (
< button
className = "inline-flex justify-between px-3 py-1.5 text-left text-sm text-gray-800 hover:bg-gray-100"
< ProgressDropdownItem
status = "skipped"
shortcutKey = "S"
label = "Skip"
onClick = { ( ) = > handleUpdateResourceProgress ( 'skipped' ) }
>
< span >
< span
className = { ` mr-2 inline-block h-2 w-2 rounded-full ${ statusColors [ 'skipped' ] } ` }
> < / span >
Skip
< / span >
< span className = "text-xs text-gray-500" > S < / span >
< / button >
/ >
) }
< / div >
) }