react-icons/fi#FiActivity TypeScript Examples
The following examples show how to use
react-icons/fi#FiActivity.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextMenu.tsx From meshtastic-web with GNU General Public License v3.0 | 5 votes |
ContextMenu = ({
items,
children,
}: ContextMenuProps): JSX.Element => {
const [visible, setVisible] = useState(false);
const [position, setPosition] = useState({ x: 0, y: 0 });
return (
<div
className="h-full"
onContextMenu={(e): void => {
e.preventDefault();
setVisible(false);
const newPosition = {
x: e.pageX,
y: e.pageY,
};
setPosition(newPosition);
setVisible(true);
}}
onClick={(): void => {
setVisible(false);
}}
>
{children}
{visible && (
<div
style={{ top: position.y, left: position.x }}
className="fixed z-50 w-60 gap-2 divide-y divide-gray-300 rounded-md border border-gray-400 font-medium drop-shadow-md backdrop-blur-xl dark:divide-gray-600 dark:border-gray-600 dark:text-gray-400"
>
{items}
<ContextItem title="Menu item" icon={<FiActivity />} />
<ContextItem title="Menu item 2" icon={<FiAperture />} />
<ContextItem
title="Menu item 3 with a very long name that should wrap"
icon={<FiTag />}
/>
</div>
)}
</div>
);
}
Example #2
Source File: index.tsx From rocketredis with MIT License | 4 votes |
Connection: React.FC<IConnectionProps> = ({ connection }) => {
const [currentConnection, setCurrentConnection] = useRecoilState(
currentConnectionState
)
const [currentDatabase, setCurrentDatabase] = useRecoilState(
currentDatabaseState
)
const setCurrentKey = useSetRecoilState(currentKeyState)
const [databases, setDatabases] = useState<IDatabase[]>([])
const [connectionLoading, setConnectionLoading] = useState(false)
const [isConnectionFailed, setIsConnectionFailed] = useState(false)
const [isEditModalOpen, toggleEditModalOpen] = useToggle(false)
const [isDeleteModalOpen, toggleDeleteModalOpen] = useToggle(false)
const { t } = useTranslation('connection')
const { addToast } = useToast()
useEffect(() => {
if (currentConnection) {
setIsConnectionFailed(false)
}
}, [currentConnection])
const isConnected = useMemo(() => {
return currentConnection?.name === connection.name
}, [currentConnection?.name, connection.name])
const handleConnect = useCallback(async () => {
if (!isConnected) {
setConnectionLoading(true)
setCurrentConnection(undefined)
setCurrentDatabase(undefined)
setCurrentKey(undefined)
try {
const databases = await loadConnectionDatabases(connection)
setDatabases(databases)
setCurrentConnection(connection)
setCurrentDatabase(undefined)
} catch {
setIsConnectionFailed(true)
} finally {
setConnectionLoading(false)
}
}
}, [
connection,
isConnected,
setCurrentConnection,
setCurrentDatabase,
setCurrentKey
])
const handleDisconnect = useCallback(async () => {
setCurrentConnection(undefined)
setCurrentDatabase(undefined)
terminateConnection()
}, [setCurrentConnection, setCurrentDatabase])
const handleRefreshDatabases = useCallback(async () => {
try {
setConnectionLoading(true)
const databases = await loadConnectionDatabases(connection)
setDatabases(databases)
} catch {
setIsConnectionFailed(true)
} finally {
setConnectionLoading(false)
}
}, [connection])
const postSavingConnection = useCallback(async () => {
toggleEditModalOpen()
setCurrentConnection(undefined)
setCurrentDatabase(undefined)
setIsConnectionFailed(false)
}, [toggleEditModalOpen, setCurrentConnection, setCurrentDatabase])
const postDeletingConnection = useCallback(async () => {
toggleDeleteModalOpen()
setCurrentConnection(undefined)
setCurrentDatabase(undefined)
terminateConnection()
}, [toggleDeleteModalOpen, setCurrentConnection, setCurrentDatabase])
const handleSelectDatabase = useCallback(
async (database: IDatabase) => {
if (!currentConnection) {
return
}
try {
await initializeConnection(currentConnection, database)
setCurrentDatabase(database)
setCurrentKey(undefined)
} catch {
addToast({
type: 'error',
title: 'Failed to connect to database',
description:
'A connection to this Redis database could not be established.'
})
}
},
[currentConnection, addToast, setCurrentDatabase, setCurrentKey]
)
return (
<>
<Container
key={connection.name}
connected={isConnected}
errored={isConnectionFailed}
>
<ContextMenuTrigger id={`connection_actions_menu:${connection.name}`}>
<button type="button" disabled={isConnected} onClick={handleConnect}>
{connectionLoading ? (
<Loading>
<FiLoader />
</Loading>
) : (
<FiDatabase />
)}
{connection.name}
<FiChevronRight />
</button>
</ContextMenuTrigger>
<ContextMenu
id={`connection_actions_menu:${connection.name}`}
className="connection-actions-menu"
>
{isConnected ? (
<MenuItem onClick={handleDisconnect}>
<DisconnectButton>
<FiMinusCircle />
{t('contextMenu.disconnect')}
</DisconnectButton>
</MenuItem>
) : (
<MenuItem onClick={handleConnect}>
<ConnectButton>
<FiActivity />
{t('contextMenu.connect')}
</ConnectButton>
</MenuItem>
)}
<MenuItem onClick={toggleEditModalOpen}>
<FiEdit2 />
{t('contextMenu.editSettings')}
</MenuItem>
{isConnected && (
<MenuItem onClick={handleRefreshDatabases}>
<FiRefreshCcw />
{t('contextMenu.refreshDatabases')}
</MenuItem>
)}
<MenuItem onClick={toggleDeleteModalOpen}>
<FiTrash />
{t('contextMenu.deleteConnection')}
</MenuItem>
</ContextMenu>
{isConnected && !!databases.length && (
<DatabaseList>
{databases.map(database => (
<Database
connected={currentDatabase?.name === database.name}
key={database.name}
onClick={() => handleSelectDatabase(database)}
type="button"
>
<strong>{database.name}</strong>
<span>
{database.keys} {t('keys')}
</span>
</Database>
))}
</DatabaseList>
)}
{isConnectionFailed && (
<ConnectionError>
{t('connectionFailed')}{' '}
<button type="button" onClick={handleConnect}>
{t('retry')}
</button>
</ConnectionError>
)}
</Container>
<ConnectionFormModal
visible={isEditModalOpen}
onRequestClose={postSavingConnection}
connectionToEdit={connection}
/>
<DeleteConnectionModal
visible={isDeleteModalOpen}
onRequestClose={postDeletingConnection}
connectionToDelete={connection}
/>
</>
)
}
Example #3
Source File: index.tsx From rocketredis with MIT License | 4 votes |
ConnectionFormModal: React.FC<ConnectionModalProps> = ({
visible,
onRequestClose,
connectionToEdit
}) => {
const formRef = useRef<FormHandles>(null)
const { addToast } = useToast()
const setConnections = useSetRecoilState(connectionsState)
const { t } = useTranslation('connectionForm')
const [testConnectionLoading, toggleTestConnectionLoading] = useToggle(false)
const [createConnectionLoading, toggleCreateConnectionLoading] = useToggle(
false
)
const handleCloseModal = useCallback(() => {
if (onRequestClose) {
onRequestClose()
}
}, [onRequestClose])
const handleCreateOrUpdateConnection = useCallback(
async (data: ConnectionFormData) => {
try {
formRef.current?.setErrors({})
const schema = Yup.object().shape({
name: Yup.string().required(),
host: Yup.string().required(),
port: Yup.number().required(),
password: Yup.string()
})
toggleCreateConnectionLoading()
await schema.validate(data, {
abortEarly: false
})
const { name, host, port, password } = data
try {
const connectionData = {
name,
host,
port: Number(port),
password
}
const connections = connectionToEdit
? updateAndGetConnections(connectionToEdit, connectionData)
: createAndGetConnections(connectionData)
setConnections(connections)
addToast({
type: 'success',
title: 'Connection saved',
description: 'You can now connect to your database!'
})
handleCloseModal()
} catch (err) {
addToast({
type: 'error',
title: 'Error saving connection',
description: err.message || 'Unexpected error occurred, try again.'
})
}
} catch (err) {
if (err instanceof Yup.ValidationError) {
const errors = getValidationErrors(err)
formRef.current?.setErrors(errors)
}
} finally {
toggleCreateConnectionLoading()
}
},
[
addToast,
setConnections,
toggleCreateConnectionLoading,
connectionToEdit,
handleCloseModal
]
)
const handleTestConnection = useCallback(async () => {
if (!formRef.current) {
return
}
const {
host,
port,
password
} = formRef.current.getData() as ConnectionFormData
try {
formRef.current?.setErrors({})
toggleTestConnectionLoading()
const schema = Yup.object().shape({
host: Yup.string().required(),
port: Yup.number().required(),
password: Yup.string()
})
const data = {
host,
port
}
await schema.validate(data, {
abortEarly: false
})
await testConnection({
host,
port: Number(port),
password
})
addToast({
type: 'success',
title: 'Connection successful',
description: 'Urrray... You can save your connection now!'
})
} catch (err) {
if (err instanceof Yup.ValidationError) {
const errors = getValidationErrors(err)
formRef.current?.setErrors(errors)
} else {
addToast({
type: 'error',
title: 'Error on connection',
description: 'Error estabilishing connection with your Redis server'
})
}
} finally {
toggleTestConnectionLoading()
}
}, [addToast, toggleTestConnectionLoading])
return (
<Modal visible={visible} onRequestClose={onRequestClose}>
<h1>
{connectionToEdit ? t('editConnectionTitle') : t('newConnectionTitle')}
</h1>
<Form
initialData={{
name: connectionToEdit?.name,
host: connectionToEdit?.host || 'localhost',
port: connectionToEdit?.port || '6379'
}}
ref={formRef}
onSubmit={handleCreateOrUpdateConnection}
>
<Input name="name" label={t('form.name')} />
<InputGroup>
<Input name="host" label={t('form.host')} />
<Input name="port" label={t('form.port')} />
</InputGroup>
<Input
type="password"
name="password"
label={t('form.password')}
hint={t('form.passwordHint')}
/>
<ActionsContainer>
<TestConnectionButton
loading={testConnectionLoading}
color="pink"
onClick={handleTestConnection}
>
<FiActivity />
{t('form.test')}
</TestConnectionButton>
<ButtonGroup>
<Button onClick={handleCloseModal} type="button" color="opaque">
{t('form.cancel')}
</Button>
<Button
loading={createConnectionLoading}
type="submit"
color="purple"
>
<FiSave />
{t('form.save')}
</Button>
</ButtonGroup>
</ActionsContainer>
</Form>
</Modal>
)
}
Example #4
Source File: Index.tsx From meshtastic-web with GNU General Public License v3.0 | 4 votes |
Settings = ({ open, setOpen }: SettingsProps): JSX.Element => {
const [modulesOpen, setModulesOpen] = useState(false);
const [channelsOpen, setChannelsOpen] = useState(false);
const moduleConfig = useAppSelector(
(state) => state.meshtastic.radio.moduleConfig,
);
const hasGps = true;
const hasWifi = true;
return (
<>
<SidebarOverlay
title="Settings"
open={open}
close={(): void => {
setOpen(false);
}}
direction="y"
>
<CollapsibleSection icon={<FiUser />} title="User">
<User />
</CollapsibleSection>
<CollapsibleSection icon={<FiSmartphone />} title="Device">
<WiFi />
</CollapsibleSection>
<CollapsibleSection icon={<FiMapPin />} title="Position">
<Position />
</CollapsibleSection>
<CollapsibleSection icon={<FiPower />} title="Power">
<Power />
</CollapsibleSection>
<CollapsibleSection icon={<FiWifi />} title="WiFi">
<WiFi />
</CollapsibleSection>
<CollapsibleSection icon={<FiTv />} title="Display">
<Display />
</CollapsibleSection>
<CollapsibleSection icon={<FiRss />} title="LoRa">
<LoRa />
</CollapsibleSection>
<ExternalSection
onClick={(): void => {
setChannelsOpen(true);
}}
icon={<FiLayers />}
title="Channels"
/>
<ExternalSection
onClick={(): void => {
setModulesOpen(true);
}}
icon={<FiPackage />}
title="Modules"
/>
<CollapsibleSection icon={<FiLayout />} title="Interface">
<Interface />
</CollapsibleSection>
</SidebarOverlay>
{/* Modules */}
<SidebarOverlay
title="Modules"
open={modulesOpen}
close={(): void => {
setModulesOpen(false);
}}
direction="x"
>
<CollapsibleSection
icon={<FiWifi />}
title="MQTT"
status={!moduleConfig.mqtt.disabled}
>
<MQTT />
</CollapsibleSection>
<CollapsibleSection
icon={<FiAlignLeft />}
title="Serial"
status={moduleConfig.serial.enabled}
>
<SerialSettingsPanel />
</CollapsibleSection>
<CollapsibleSection
icon={<FiBell />}
title="External Notifications"
status={moduleConfig.extNotification.enabled}
>
<ExternalNotificationsSettingsPlanel />
</CollapsibleSection>
<CollapsibleSection
icon={<FiFastForward />}
title="Store & Forward"
status={moduleConfig.storeForward.enabled}
>
<StoreForwardSettingsPanel />
</CollapsibleSection>
<CollapsibleSection
icon={<FiRss />}
title="Range Test"
status={moduleConfig.rangeTest.enabled}
>
<RangeTestSettingsPanel />
</CollapsibleSection>
<CollapsibleSection
icon={<FiActivity />}
title="Telemetry"
status={true}
>
<Telemetry />
</CollapsibleSection>
<CollapsibleSection
icon={<FiMessageSquare />}
title="Canned Message"
status={moduleConfig.cannedMessage.enabled}
>
<CannedMessage />
</CollapsibleSection>
</SidebarOverlay>
{/* End Modules */}
{/* Channels */}
<SidebarOverlay
title="Channels"
open={channelsOpen}
close={(): void => {
setChannelsOpen(false);
}}
direction="x"
>
<ChannelsGroup />
</SidebarOverlay>
{/* End Channels */}
</>
);
}