| 1 | import { Text } from "ink"; |
| 2 | import React, { useMemo } from "react"; |
| 3 | |
| 4 | import { useServices } from "../hooks/useService.js"; |
| 5 | import { |
| 6 | SERVICE_NAMES, |
| 7 | UpdateServiceState, |
| 8 | UpdateStatus, |
| 9 | } from "../services/types.js"; |
| 10 | |
| 11 | import { useTerminalSize } from "./hooks/useTerminalSize.js"; |
| 12 | |
| 13 | interface UpdateNotificationProps { |
| 14 | isRemoteMode?: boolean; |
| 15 | } |
| 16 | const UpdateNotification: React.FC<UpdateNotificationProps> = ({ |
| 17 | isRemoteMode = false, |
| 18 | }) => { |
| 19 | const { columns } = useTerminalSize(); |
| 20 | |
| 21 | const { services } = useServices<{ |
| 22 | update: UpdateServiceState; |
| 23 | }>([SERVICE_NAMES.UPDATE]); |
| 24 | |
| 25 | const color = useMemo(() => { |
| 26 | switch (services.update?.status) { |
| 27 | case UpdateStatus.UPDATING: |
| 28 | case UpdateStatus.CHECKING: |
| 29 | return "yellow"; |
| 30 | case UpdateStatus.UPDATED: |
| 31 | return "green"; |
| 32 | case UpdateStatus.ERROR: |
| 33 | return "red"; |
| 34 | default: |
| 35 | return "dim"; |
| 36 | } |
| 37 | }, [services.update?.status]); |
| 38 | |
| 39 | const text = useMemo(() => { |
| 40 | if (!services.update?.message) { |
| 41 | return "Continue CLI"; |
| 42 | } |
| 43 | |
| 44 | return services.update.message; |
| 45 | }, [columns, services.update?.message]); |
| 46 | |
| 47 | if (!services.update?.isUpdateAvailable && isRemoteMode) { |
| 48 | return <Text color="cyan">◉ Remote Mode</Text>; |
| 49 | } |
| 50 | |
| 51 | return <Text color={color}>{`◉ ${text}`}</Text>; |
| 52 | }; |
| 53 | |
| 54 | export { UpdateNotification }; |