5 changed files with 121 additions and 50 deletions
@ -40,7 +40,7 @@ specifiers: |
|||||
react-hook-form: ^7.27.0 |
react-hook-form: ^7.27.0 |
||||
react-icons: ^4.3.1 |
react-icons: ^4.3.1 |
||||
react-json-pretty: ^2.2.0 |
react-json-pretty: ^2.2.0 |
||||
react-multi-select-component: ^4.2.1 |
react-multi-select-component: ^4.2.2 |
||||
react-qr-code: ^2.0.3 |
react-qr-code: ^2.0.3 |
||||
react-redux: ^7.2.6 |
react-redux: ^7.2.6 |
||||
react-use-clipboard: ^1.0.7 |
react-use-clipboard: ^1.0.7 |
||||
@ -75,7 +75,7 @@ dependencies: |
|||||
react-hook-form: 7.27[email protected] |
react-hook-form: 7.27[email protected] |
||||
react-icons: 4.3[email protected] |
react-icons: 4.3[email protected] |
||||
react-json-pretty: 2.2[email protected][email protected] |
react-json-pretty: 2.2[email protected][email protected] |
||||
react-multi-select-component: 4.2.1[email protected][email protected] |
react-multi-select-component: 4.2.2[email protected][email protected] |
||||
react-qr-code: 2.0[email protected] |
react-qr-code: 2.0[email protected] |
||||
react-redux: 7.2[email protected][email protected] |
react-redux: 7.2[email protected][email protected] |
||||
react-use-clipboard: 1.0[email protected][email protected] |
react-use-clipboard: 1.0[email protected][email protected] |
||||
@ -4875,8 +4875,8 @@ packages: |
|||||
react-dom: 17.0[email protected] |
react-dom: 17.0[email protected] |
||||
dev: false |
dev: false |
||||
|
|
||||
/react-multi-select-component/4.2.1[email protected][email protected]: |
/react-multi-select-component/4.2.2[email protected][email protected]: |
||||
resolution: {integrity: sha512-wRteBq1pqKLlYX/ob8I1aBapPokQiRzOJzVqJDVVTHb0Ap/QWXVE4OXE2xwhVf3qmmYvOguvOKQQbQiEYxhONA==} |
resolution: {integrity: sha512-FvlHp1a4LzwJr121mq4q8NnO4l9HgDo7Z9gk4uCzhRygc78QmqoEcgKEwfcfaQKJp2HAZw4b31P87ex2mLK38A==} |
||||
peerDependencies: |
peerDependencies: |
||||
react: ^16 || ^17 |
react: ^16 || ^17 |
||||
react-dom: ^16 || ^17 |
react-dom: ^16 || ^17 |
||||
|
|||||
@ -0,0 +1,62 @@ |
|||||
|
import React from 'react'; |
||||
|
|
||||
|
import { useAppSelector } from '@app/hooks/useAppSelector'; |
||||
|
import { Protobuf } 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'; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
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; |
||||
|
}; |
||||
|
|
||||
|
return ( |
||||
|
<div className="flex h-full w-full select-none flex-col gap-4 p-4"> |
||||
|
<div className="flex w-full select-none flex-col gap-2 overflow-y-auto rounded-md p-4 shadow-md dark:bg-primaryDark"> |
||||
|
{logs.map((log, index) => ( |
||||
|
<div key={index} className="flex gap-2"> |
||||
|
<div className="text-sm font-light dark:text-gray-400"> |
||||
|
{log.date.toISOString()} |
||||
|
</div> |
||||
|
<div>[{log.emitter}]</div> |
||||
|
<div className={`text-sm font-medium ${logColor(log.level)}`}> |
||||
|
[{Protobuf.LogRecord_Level[log.level]}] |
||||
|
</div> |
||||
|
<div style={{ color: stringToColour(log.emitter) }}> |
||||
|
{stringToColour(log.emitter)} |
||||
|
</div> |
||||
|
<div>{log.message}</div> |
||||
|
</div> |
||||
|
))} |
||||
|
</div> |
||||
|
</div> |
||||
|
); |
||||
|
}; |
||||
Loading…
Reference in new issue