Modal and connection modal improvements
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import { AnimatePresence, m } from 'framer-motion';
|
import { m } from 'framer-motion';
|
||||||
|
|
||||||
import { BLE } from '@components/connection/BLE';
|
import { BLE } from '@components/connection/BLE';
|
||||||
import { HTTP } from '@components/connection/HTTP';
|
import { HTTP } from '@components/connection/HTTP';
|
||||||
@@ -49,17 +49,16 @@ export const Connection = (): JSX.Element => {
|
|||||||
}, [meshtasticState.ready, dispatch]);
|
}, [meshtasticState.ready, dispatch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence>
|
|
||||||
{appState.connectionModalOpen && (
|
|
||||||
<Modal
|
<Modal
|
||||||
title="Connect to a device"
|
title="Connect to a device"
|
||||||
|
open={appState.connectionModalOpen}
|
||||||
onClose={(): void => {
|
onClose={(): void => {
|
||||||
dispatch(closeConnectionModal());
|
dispatch(closeConnectionModal());
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="flex max-w-3xl flex-col gap-4 md:flex-row">
|
<div className="flex max-w-3xl flex-col gap-4 md:flex-row">
|
||||||
<div className="md:w-1/2">
|
<div className="flex flex-col md:w-1/2">
|
||||||
<div className="space-y-2">
|
<div className="flex flex-grow flex-col space-y-2">
|
||||||
<Select
|
<Select
|
||||||
label="Connection Method"
|
label="Connection Method"
|
||||||
optionsEnum={connType}
|
optionsEnum={connType}
|
||||||
@@ -108,9 +107,7 @@ export const Connection = (): JSX.Element => {
|
|||||||
exit={{ opacity: 0 }}
|
exit={{ opacity: 0 }}
|
||||||
className="m-auto h-40 w-40 text-green-500"
|
className="m-auto h-40 w-40 text-green-500"
|
||||||
src={`/placeholders/${
|
src={`/placeholders/${
|
||||||
appState.darkMode
|
appState.darkMode ? 'View Code Dark.svg' : 'View Code.svg'
|
||||||
? 'View Code Dark.svg'
|
|
||||||
: 'View Code.svg'
|
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -134,7 +131,5 @@ export const Connection = (): JSX.Element => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,13 +36,12 @@ export const BLE = ({ connecting }: BLEProps): JSX.Element => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={onSubmit} className="space-y-2">
|
<form onSubmit={onSubmit} className="flex flex-grow flex-col">
|
||||||
{bleDevices.map((device, index) => (
|
<div className="flex flex-grow flex-col gap-2 overflow-y-auto rounded-md border border-gray-300 bg-gray-200 p-2 dark:border-gray-600 dark:bg-secondaryDark dark:text-gray-400">
|
||||||
|
{bleDevices.length > 0 ? (
|
||||||
|
bleDevices.map((device, index) => (
|
||||||
<div
|
<div
|
||||||
onClick={async (): Promise<void> => {
|
className="flex justify-between rounded-md bg-white p-2 dark:bg-primaryDark dark:text-white"
|
||||||
await setConnection(connType.BLE);
|
|
||||||
}}
|
|
||||||
className="flex justify-between rounded-md bg-gray-700 p-2 dark:text-white"
|
|
||||||
key={index}
|
key={index}
|
||||||
>
|
>
|
||||||
<div className="my-auto">{device.name}</div>
|
<div className="my-auto">{device.name}</div>
|
||||||
@@ -55,7 +54,13 @@ export const BLE = ({ connecting }: BLEProps): JSX.Element => {
|
|||||||
disabled={connecting}
|
disabled={connecting}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))
|
||||||
|
) : (
|
||||||
|
<div className="m-auto">
|
||||||
|
<p>No previously connected devices found</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<Button
|
<Button
|
||||||
className="mt-2 ml-auto"
|
className="mt-2 ml-auto"
|
||||||
onClick={async (): Promise<void> => {
|
onClick={async (): Promise<void> => {
|
||||||
|
|||||||
@@ -38,11 +38,12 @@ export const Serial = ({ connecting }: SerialProps): JSX.Element => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={onSubmit} className="space-y-2">
|
<form onSubmit={onSubmit} className="flex flex-grow flex-col">
|
||||||
|
<div className="flex flex-grow flex-col gap-2 overflow-y-auto rounded-md border border-gray-300 bg-gray-200 p-2 dark:border-gray-600 dark:bg-secondaryDark dark:text-gray-400">
|
||||||
{serialDevices.length > 0 ? (
|
{serialDevices.length > 0 ? (
|
||||||
serialDevices.map((device, index) => (
|
serialDevices.map((device, index) => (
|
||||||
<div
|
<div
|
||||||
className="flex justify-between rounded-md bg-secondaryDark p-2 dark:text-white"
|
className="flex justify-between rounded-md bg-white p-2 dark:bg-primaryDark dark:text-white"
|
||||||
key={index}
|
key={index}
|
||||||
>
|
>
|
||||||
<div className="my-auto flex gap-4">
|
<div className="my-auto flex gap-4">
|
||||||
@@ -54,7 +55,6 @@ export const Serial = ({ connecting }: SerialProps): JSX.Element => {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<IconButton
|
<IconButton
|
||||||
nested
|
|
||||||
onClick={async (): Promise<void> => {
|
onClick={async (): Promise<void> => {
|
||||||
dispatch(
|
dispatch(
|
||||||
setConnectionParams({
|
setConnectionParams({
|
||||||
@@ -72,10 +72,11 @@ export const Serial = ({ connecting }: SerialProps): JSX.Element => {
|
|||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<div className="h-40 rounded-md border border-gray-300 dark:border-gray-600">
|
<div className="m-auto">
|
||||||
<p>No previously connected devices found</p>
|
<p>No previously connected devices found</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
<Button
|
<Button
|
||||||
className="mt-2 ml-auto"
|
className="mt-2 ml-auto"
|
||||||
onClick={async (): Promise<void> => {
|
onClick={async (): Promise<void> => {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export const Card = ({
|
|||||||
initial={{ opacity: 0 }}
|
initial={{ opacity: 0 }}
|
||||||
animate={{ opacity: 1 }}
|
animate={{ opacity: 1 }}
|
||||||
exit={{ opacity: 0 }}
|
exit={{ opacity: 0 }}
|
||||||
|
transition={{ duration: 0.1 }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</m.div>
|
</m.div>
|
||||||
|
|||||||
@@ -1,33 +1,45 @@
|
|||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
|
|
||||||
import { m } from 'framer-motion';
|
import { AnimatePresence, m } from 'framer-motion';
|
||||||
import { FiX } from 'react-icons/fi';
|
import { FiX } from 'react-icons/fi';
|
||||||
|
|
||||||
import { useAppSelector } from '@hooks/useAppSelector';
|
import { useAppSelector } from '@hooks/useAppSelector';
|
||||||
|
|
||||||
import { IconButton } from './button/IconButton';
|
import { IconButton } from './button/IconButton';
|
||||||
import { Card } from './Card';
|
import { Card, CardProps } from './Card';
|
||||||
|
|
||||||
export interface ModalProps {
|
export interface ModalProps extends CardProps {
|
||||||
title: string;
|
open: boolean;
|
||||||
|
bgDismiss?: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
actions?: React.ReactNode;
|
|
||||||
children: React.ReactNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Modal = ({
|
export const Modal = ({
|
||||||
title,
|
open,
|
||||||
|
bgDismiss,
|
||||||
onClose,
|
onClose,
|
||||||
actions,
|
actions,
|
||||||
children,
|
...props
|
||||||
}: ModalProps): JSX.Element => {
|
}: ModalProps): JSX.Element => {
|
||||||
const darkMode = useAppSelector((state) => state.app.darkMode);
|
const darkMode = useAppSelector((state) => state.app.darkMode);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<m.div className={`fixed inset-0 z-30 ${darkMode ? 'dark' : ''}`}>
|
<AnimatePresence>
|
||||||
|
{open && (
|
||||||
<m.div
|
<m.div
|
||||||
className="fixed h-full w-full backdrop-blur-sm backdrop-filter"
|
className={`fixed inset-0 ${darkMode ? 'dark' : ''} ${
|
||||||
onClick={onClose}
|
open ? 'z-30' : 'z-0'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<m.div
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
exit={{ opacity: 0 }}
|
||||||
|
transition={{ duration: 0.1 }}
|
||||||
|
className="fixed h-full w-full backdrop-blur-md backdrop-filter"
|
||||||
|
onClick={(): void => {
|
||||||
|
bgDismiss && onClose();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<m.div className="text-center ">
|
<m.div className="text-center ">
|
||||||
<span
|
<span
|
||||||
@@ -40,19 +52,23 @@ export const Modal = ({
|
|||||||
<Card
|
<Card
|
||||||
border
|
border
|
||||||
draggable
|
draggable
|
||||||
title={title}
|
|
||||||
actions={
|
actions={
|
||||||
<>
|
<div className="flex gap-2">
|
||||||
{actions}
|
{actions}
|
||||||
<IconButton tooltip="Close" icon={<FiX />} onClick={onClose} />
|
<IconButton
|
||||||
</>
|
tooltip="Close"
|
||||||
|
icon={<FiX />}
|
||||||
|
onClick={onClose}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
className="relative flex-col gap-4"
|
className="relative flex-col gap-4"
|
||||||
>
|
{...props}
|
||||||
{children}
|
/>
|
||||||
</Card>
|
|
||||||
</div>
|
</div>
|
||||||
</m.div>
|
</m.div>
|
||||||
</m.div>
|
</m.div>
|
||||||
|
)}
|
||||||
|
</AnimatePresence>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ export const BottomNav = (): JSX.Element => {
|
|||||||
</BottomNavItem>
|
</BottomNavItem>
|
||||||
|
|
||||||
<VersionInfo
|
<VersionInfo
|
||||||
visible={showVersionInfo}
|
modalOpen={showVersionInfo}
|
||||||
onClose={(): void => {
|
onClose={(): void => {
|
||||||
setShowVersionInfo(false);
|
setShowVersionInfo(false);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import { AnimatePresence } from 'framer-motion';
|
|
||||||
import { MdUpgrade } from 'react-icons/md';
|
import { MdUpgrade } from 'react-icons/md';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
@@ -38,12 +37,12 @@ export interface Commit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface VersionInfoProps {
|
export interface VersionInfoProps {
|
||||||
visible: boolean;
|
modalOpen: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const VersionInfo = ({
|
export const VersionInfo = ({
|
||||||
visible,
|
modalOpen,
|
||||||
onClose,
|
onClose,
|
||||||
}: VersionInfoProps): JSX.Element => {
|
}: VersionInfoProps): JSX.Element => {
|
||||||
const appState = useAppSelector((state) => state.app);
|
const appState = useAppSelector((state) => state.app);
|
||||||
@@ -67,13 +66,13 @@ export const VersionInfo = ({
|
|||||||
dispatch(setUpdateAvaliable(true));
|
dispatch(setUpdateAvaliable(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [data]);
|
}, [data, dispatch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence>
|
|
||||||
{visible && (
|
|
||||||
<Modal
|
<Modal
|
||||||
|
open={modalOpen}
|
||||||
title="Version Info"
|
title="Version Info"
|
||||||
|
bgDismiss
|
||||||
actions={
|
actions={
|
||||||
// TODO: Check if version is hosted, and merge pwa update button here
|
// TODO: Check if version is hosted, and merge pwa update button here
|
||||||
appState.updateAvaliable && (
|
appState.updateAvaliable && (
|
||||||
@@ -98,9 +97,7 @@ export const VersionInfo = ({
|
|||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="my-auto text-xs dark:text-gray-400">
|
<div className="my-auto text-xs dark:text-gray-400">
|
||||||
{new Date(
|
{new Date(commit.commit.committer.date).toLocaleDateString()}
|
||||||
commit.commit.committer.date,
|
|
||||||
).toLocaleDateString()}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="my-auto font-mono text-sm">
|
<div className="my-auto font-mono text-sm">
|
||||||
{commit.sha.substring(0, 7)}
|
{commit.sha.substring(0, 7)}
|
||||||
@@ -110,7 +107,5 @@ export const VersionInfo = ({
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user