From 3f1297411d9280d62de1d0832352c4cf6209b924 Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Tue, 15 Feb 2022 21:31:51 +1100 Subject: [PATCH] Lokking page work --- index.html | 4 + package.json | 2 +- pnpm-lock.yaml | 8 +- src/components/Connection.tsx | 6 +- src/pages/Extensions/Logs.tsx | 149 +++++++++++++++++++++++----------- tailwind.config.cjs | 1 + 6 files changed, 114 insertions(+), 56 deletions(-) diff --git a/index.html b/index.html index 9bd27777..b21ea392 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,10 @@ + {
{state.logs.map((log, index) => (
-
[{log.date.toISOString()}]
-
[{log.emitter}]
-
{log.message}
+
+ {log.message} +
))}
diff --git a/src/pages/Extensions/Logs.tsx b/src/pages/Extensions/Logs.tsx index ffe5b1d5..b3e45fc7 100644 --- a/src/pages/Extensions/Logs.tsx +++ b/src/pages/Extensions/Logs.tsx @@ -1,62 +1,115 @@ -import React from 'react'; +import type React from 'react'; + +import { m } from 'framer-motion'; +import { FiArrowRight } from 'react-icons/fi'; import { useAppSelector } from '@app/hooks/useAppSelector'; -import { Protobuf } from '@meshtastic/meshtasticjs'; +import { Protobuf, Types } from '@meshtastic/meshtasticjs'; export const Logs = (): JSX.Element => { const logs = useAppSelector((state) => state.meshtastic.logs); - const logColor = (level: Protobuf.LogRecord_Level): string => { - switch (level) { - case Protobuf.LogRecord_Level.UNSET: - return 'text-blue-500'; - case Protobuf.LogRecord_Level.CRITICAL: - return 'text-blue-500'; - case Protobuf.LogRecord_Level.ERROR: - return 'text-blue-500'; - case Protobuf.LogRecord_Level.WARNING: - return 'text-blue-500'; - case Protobuf.LogRecord_Level.INFO: - return 'text-blue-500'; - case Protobuf.LogRecord_Level.DEBUG: - return 'text-blue-500'; - case Protobuf.LogRecord_Level.TRACE: - return 'text-blue-500'; - } + type lookupType = { [key: number]: string }; + + const emitterLookup: lookupType = { + [Types.Emitter.sendPacket]: 'text-blue-500', + [Types.Emitter.sendText]: 'text-blue-500', + [Types.Emitter.sendPacket]: 'text-blue-500', + [Types.Emitter.sendRaw]: 'text-blue-500', + [Types.Emitter.setPreferences]: 'text-blue-500', + [Types.Emitter.confirmSetPreferences]: 'text-blue-500', + [Types.Emitter.setOwner]: 'text-blue-500', + [Types.Emitter.setChannel]: 'text-blue-500', + [Types.Emitter.confirmSetChannel]: 'text-blue-500', + [Types.Emitter.deleteChannel]: 'text-blue-500', + [Types.Emitter.getChannel]: 'text-blue-500', + [Types.Emitter.getAllChannels]: 'text-blue-500', + [Types.Emitter.getPreferences]: 'text-blue-500', + [Types.Emitter.getOwner]: 'text-blue-500', + [Types.Emitter.configure]: 'text-blue-500', + [Types.Emitter.handleFromRadio]: 'text-blue-500', + [Types.Emitter.handleMeshPacket]: 'text-blue-500', + [Types.Emitter.connect]: 'text-blue-500', + [Types.Emitter.ping]: 'text-blue-500', + [Types.Emitter.readFromRadio]: 'text-blue-500', + [Types.Emitter.writeToRadio]: 'text-blue-500', + [Types.Emitter.setDebugMode]: 'text-blue-500', }; - const stringToColour = (str: string) => { - let hash = 0; - for (let i = 0; i < str.length; i++) { - hash = str.charCodeAt(i) + ((hash << 5) - hash); - } - let colour = '#'; - for (let i = 0; i < 3; i++) { - const value = (hash >> (i * 8)) & 0xff; - colour += ('00' + value.toString(16)).substr(-2); - } - return colour; + const levelLookup: lookupType = { + [Protobuf.LogRecord_Level.UNSET]: 'text-green-500', + [Protobuf.LogRecord_Level.CRITICAL]: 'text-purple-500', + [Protobuf.LogRecord_Level.ERROR]: 'text-red-500', + [Protobuf.LogRecord_Level.WARNING]: 'text-orange-500', + [Protobuf.LogRecord_Level.INFO]: 'text-blue-500', + [Protobuf.LogRecord_Level.DEBUG]: 'text-neutral-500', + [Protobuf.LogRecord_Level.TRACE]: 'text-slate-500', }; return ( -
-
- {logs.map((log, index) => ( -
-
- {log.date.toISOString()} -
-
[{log.emitter}]
-
- [{Protobuf.LogRecord_Level[log.level]}] -
-
- {stringToColour(log.emitter)} -
-
{log.message}
-
- ))} -
+
+ + {/* \/ flex flex-col gap-2 */} + + {logs.map((log, index) => ( + + +
+ +
+
+ + {log.date + .toLocaleString(undefined, { + year: 'numeric', + month: '2-digit', + day: '2-digit', + + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + }) + .replaceAll('/', '-') + .replace(',', '')} + + +
+ [{Types.EmitterScope[log.scope]}.{Types.Emitter[log.emitter]}] +
+
+ + [{Protobuf.LogRecord_Level[log.level]}]{/* */} + + + + ))} + +
{log.message}
); }; + +const Wrapper = ({ + className, + children, +}: { + className?: string; + children: React.ReactNode; +}): JSX.Element => ( + + + {children} + + +); diff --git a/tailwind.config.cjs b/tailwind.config.cjs index cc3b1c35..5e922d40 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -6,6 +6,7 @@ module.exports = { theme: { fontFamily: { sans: ['Inter var', ...defaultTheme.fontFamily.sans], + mono: ['Cascadia Code', ...defaultTheme.fontFamily.mono], }, extend: { colors: {