import React from 'react'; import { AnimatePresence } from 'framer-motion'; import { MdUpgrade } from 'react-icons/md'; import useSWR from 'swr'; import { connectionUrl } from '@app/core/connection.js'; import { setUpdateAvaliable } from '@app/core/slices/appSlice'; import { fetcher } from '@app/core/utils/fetcher'; import { useAppDispatch } from '@app/hooks/useAppDispatch'; import { useAppSelector } from '@app/hooks/useAppSelector'; import { Modal } from '@components/generic/Modal'; import { IconButton } from '../generic/button/IconButton'; export interface Commit { sha: string; node_id: string; commit: { author: string; committer: { date: string; email: string; mame: string; }; message: string; tree: { sha: string; url: string; }; url: string; comment_count: number; }; url: string; html_url: string; comments_url: string; } export interface VersionInfoProps { visible: boolean; onClose: () => void; } export const VersionInfo = ({ visible, onClose, }: VersionInfoProps): JSX.Element => { const appState = useAppSelector((state) => state.app); const dispatch = useAppDispatch(); const { data } = useSWR( 'https://api.github.com/repos/meshtastic/meshtastic-web/commits?per_page=100', fetcher, { revalidateOnFocus: false, }, ); React.useEffect(() => { if (data) { const index = data.findIndex( (commit) => commit.sha.substring(0, 7) === process.env.COMMIT_HASH, ); if (index === -1 || index > 0) { dispatch(setUpdateAvaliable(true)); } } }, [data]); return ( {visible && ( } /> ) } onClose={(): void => { onClose(); }} >
{data && data.map((commit) => (
{new Date( commit.commit.committer.date, ).toLocaleDateString()}
{commit.sha.substring(0, 7)}
{commit.commit.message}
))}
)}
); };