From fae5959d2fa295d82a6c2106725b48a72feee903 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 22 Apr 2021 17:03:33 +1000 Subject: [PATCH] Format tsx files --- web-chat/package.json | 8 ++-- web-chat/src/App.tsx | 59 +++++++++++++----------- web-chat/src/MessageInput.tsx | 33 ++++++++------ web-chat/src/Room.tsx | 86 ++++++++++++++++++----------------- 4 files changed, 100 insertions(+), 86 deletions(-) diff --git a/web-chat/package.json b/web-chat/package.json index eb5629be9b..dd304fbc74 100644 --- a/web-chat/package.json +++ b/web-chat/package.json @@ -27,11 +27,11 @@ "eject": "react-scripts eject", "fix": "run-s fix:*", "test": "run-s build test:*", - "test:lint": "eslint src --ext .ts", - "test:prettier": "prettier \"src/**/*.ts\" --list-different", + "test:lint": "eslint src --ext .ts --ext .tsx", + "test:prettier": "prettier \"src/**/*.{ts,tsx}\" --list-different", "test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"", - "fix:prettier": "prettier \"src/**/*.ts\" --write", - "fix:lint": "eslint src --ext .ts --fix" + "fix:prettier": "prettier \"src/**/*.{ts,tsx}\" --write", + "fix:lint": "eslint src --ext .ts --ext .tsx --fix" }, "eslintConfig": { "extends": [ diff --git a/web-chat/src/App.tsx b/web-chat/src/App.tsx index 48138bb966..4b1437261d 100644 --- a/web-chat/src/App.tsx +++ b/web-chat/src/App.tsx @@ -13,14 +13,13 @@ import { WakuContext } from './WakuContext'; export const ChatContentTopic = 'dingpu'; interface State { - messages: ChatMessage[], - waku?: Waku + messages: ChatMessage[]; + waku?: Waku; } export default function App() { let [state, setState] = useState({ messages: [] }); - useEffect(() => { async function initWaku() { try { @@ -28,9 +27,9 @@ export default function App() { config: { pubsub: { enabled: true, - emitSelf: true - } - } + emitSelf: true, + }, + }, }); setState(({ messages }) => { @@ -40,12 +39,14 @@ export default function App() { // FIXME: Connect to a go-waku instance by default, temporary hack until // we have a go-waku instance in the fleet waku.libp2p.peerStore.addressBook.add( - PeerId.createFromB58String('16Uiu2HAmVVi6Q4j7MAKVibquW8aA27UNrA4Q8Wkz9EetGViu8ZF1'), - [multiaddr('/ip4/134.209.113.86/tcp/9001/ws')]); + PeerId.createFromB58String( + '16Uiu2HAmVVi6Q4j7MAKVibquW8aA27UNrA4Q8Wkz9EetGViu8ZF1' + ), + [multiaddr('/ip4/134.209.113.86/tcp/9001/ws')] + ); } catch (e) { console.log('Issue starting waku ', e); } - } const handleNewMessages = (event: { data: Uint8Array }) => { @@ -57,7 +58,6 @@ export default function App() { console.log('setState on ', messages); setState({ messages, waku: state.waku }); } - }; if (!state.waku) { @@ -69,7 +69,10 @@ export default function App() { // To clean up listener when component unmounts return () => { - state.waku?.libp2p.pubsub.removeListener(RelayDefaultTopic, handleNewMessages); + state.waku?.libp2p.pubsub.removeListener( + RelayDefaultTopic, + handleNewMessages + ); }; } }); @@ -84,7 +87,9 @@ export default function App() { } else { switch (cmd) { case '/help': - commandResponses.push('/connect : connect to the given peer'); + commandResponses.push( + '/connect : connect to the given peer' + ); commandResponses.push('/help: Display this help'); break; case '/connect': @@ -100,7 +105,8 @@ export default function App() { } else { waku.libp2p.peerStore.addressBook.add( PeerId.createFromB58String(peerId), - [peerMultiaddr]); + [peerMultiaddr] + ); } } catch (e) { commandResponses.push('Invalid multaddr: ' + e); @@ -109,24 +115,23 @@ export default function App() { break; case '/peers': waku.libp2p.peerStore.peers.forEach((peer, peerId) => { - commandResponses.push(peerId + ":") - let addresses = " addresses: [" - peer.addresses.forEach(({multiaddr}) => { - addresses += " " + multiaddr.toString() + ","; - }) - addresses = addresses.replace(/,$/,""); - addresses += "]"; + commandResponses.push(peerId + ':'); + let addresses = ' addresses: ['; + peer.addresses.forEach(({ multiaddr }) => { + addresses += ' ' + multiaddr.toString() + ','; + }); + addresses = addresses.replace(/,$/, ''); + addresses += ']'; commandResponses.push(addresses); - let protos = " protos: ["; + let protos = ' protos: ['; protos += peer.protocols; - protos+= "]" - commandResponses.push(protos) - }) + protos += ']'; + commandResponses.push(protos); + }); break; default: commandResponses.push('Unknown Command'); } - } setState(({ waku, messages }) => { commandResponses.forEach((res) => { @@ -137,8 +142,8 @@ export default function App() { }; return ( -
-
+
+
diff --git a/web-chat/src/MessageInput.tsx b/web-chat/src/MessageInput.tsx index 9ac2d340a2..760c544bf9 100644 --- a/web-chat/src/MessageInput.tsx +++ b/web-chat/src/MessageInput.tsx @@ -26,24 +26,29 @@ export default function MessageInput(props: Props) { }; return ( - + - - diff --git a/web-chat/src/Room.tsx b/web-chat/src/Room.tsx index 308df11bd2..b1f20a9339 100644 --- a/web-chat/src/Room.tsx +++ b/web-chat/src/Room.tsx @@ -1,10 +1,4 @@ -import { - Box, - Grid, - List, - ListItem, - ListItemText -} from '@material-ui/core'; +import { Box, Grid, List, ListItem, ListItemText } from '@material-ui/core'; import React, { useState } from 'react'; import { ChatMessage } from 'waku-chat/chat_message'; import { WakuMessage } from 'waku/waku_message'; @@ -13,66 +7,76 @@ import MessageInput from './MessageInput'; import { useWaku } from './WakuContext'; interface Props { - lines: ChatMessage[], + lines: ChatMessage[]; commandHandler: (cmd: string) => void; } -export default function Room (props :Props) { +export default function Room(props: Props) { let [messageToSend, setMessageToSend] = useState(''); const { waku } = useWaku(); const messageHandler = (msg: string) => { setMessageToSend(msg); - } + }; const sendMessage = async () => { if (messageToSend.startsWith('/')) { - props.commandHandler(messageToSend) + props.commandHandler(messageToSend); } else { - const chatMessage = new ChatMessage(new Date(), 'web-chat', messageToSend); - const wakuMsg = WakuMessage.fromBytes(chatMessage.encode(), ChatContentTopic); + const chatMessage = new ChatMessage( + new Date(), + 'web-chat', + messageToSend + ); + const wakuMsg = WakuMessage.fromBytes( + chatMessage.encode(), + ChatContentTopic + ); await waku!.relay.send(wakuMsg); } - } - - return ( - - - - - - - - - - - + }; + return ( + + + + + - ); + + + + + + ); } interface LinesProps { - messages: ChatMessage[] + messages: ChatMessage[]; } const Lines = (props: LinesProps) => { const renderedLines = []; for (const i in props.messages) { - renderedLines.push( - - ); + renderedLines.push( + + + + ); } - return ( - - {renderedLines} - - ); + return {renderedLines}; }; // TODO: Make it a proper component @@ -82,7 +86,7 @@ function printMessage(chatMsg: ChatMessage) { day: 'numeric', hour: 'numeric', minute: '2-digit', - hour12: false + hour12: false, }); return `<${timestamp}> ${chatMsg.nick}: ${chatMsg.message}`; }