Merge pull request #257 from waku-org/feat/setup-tailwind

feat(web-chat): setup tailwind & remove @livechat/ui-kit
This commit is contained in:
Danish Arora 2023-08-03 13:10:26 +05:30 committed by GitHub
commit 8192b964db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 310 additions and 1144 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,6 @@
"private": true, "private": true,
"homepage": "/web-chat", "homepage": "/web-chat",
"dependencies": { "dependencies": {
"@livechat/ui-kit": "^0.5.0-24",
"@multiformats/multiaddr": "11.0.7", "@multiformats/multiaddr": "11.0.7",
"@waku/dns-discovery": "^0.0.15", "@waku/dns-discovery": "^0.0.15",
"@waku/interfaces": "^0.0.16", "@waku/interfaces": "^0.0.16",
@ -30,6 +29,7 @@
"prettier": "^2.7.1", "prettier": "^2.7.1",
"protons": "^5.1.0", "protons": "^5.1.0",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"tailwindcss": "^3.3.3",
"typescript": "^4.9.3", "typescript": "^4.9.3",
"url": "^0.11.0" "url": "^0.11.0"
}, },

View File

@ -1,38 +0,0 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View File

@ -1,4 +1,3 @@
import "./App.css";
import handleCommand from "./command"; import handleCommand from "./command";
import Room from "./Room"; import Room from "./Room";
import { Message } from "./Message"; import { Message } from "./Message";

View File

@ -1,9 +1,4 @@
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import {
Message as LiveMessage,
MessageText,
MessageList,
} from "@livechat/ui-kit";
import { Message } from "./Message"; import { Message } from "./Message";
interface Props { interface Props {
@ -12,25 +7,28 @@ interface Props {
export default function ChatList(props: Props) { export default function ChatList(props: Props) {
const renderedMessages = props.messages.map((message) => ( const renderedMessages = props.messages.map((message) => (
<LiveMessage <div
key={ key={
message.nick + message.nick +
message.payloadAsUtf8 + message.payloadAsUtf8 +
message.timestamp.valueOf() + message.timestamp.valueOf() +
message.sentTimestamp?.valueOf() message.sentTimestamp?.valueOf()
} }
authorName={message.nick} className="flex flex-col p-2 border-b border-gray-200"
date={formatDisplayDate(message)}
> >
<MessageText>{message.payloadAsUtf8}</MessageText> <span className="text-sm text-gray-500">{message.nick}</span>
</LiveMessage> <span className="text-sm text-gray-500">
{formatDisplayDate(message)}
</span>
<p className="text-gray-700">{message.payloadAsUtf8}</p>
</div>
)); ));
return ( return (
<MessageList active containScrollInSubtree> <div className="overflow-y-auto h-full">
{renderedMessages} {renderedMessages}
<AlwaysScrollToBottom messages={props.messages} /> <AlwaysScrollToBottom messages={props.messages} />
</MessageList> </div>
); );
} }
@ -45,13 +43,13 @@ function formatDisplayDate(message: Message): string {
} }
const AlwaysScrollToBottom = (props: { messages: Message[] }) => { const AlwaysScrollToBottom = (props: { messages: Message[] }) => {
const elementRef = useRef<HTMLDivElement>(); const elementRef = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
// @ts-ignore if (elementRef.current) {
elementRef.current.scrollIntoView(); elementRef.current.scrollIntoView();
}
}, [props.messages]); }, [props.messages]);
// @ts-ignore
return <div ref={elementRef} />; return <div ref={elementRef} />;
}; };

View File

@ -1,14 +1,6 @@
import { ChangeEvent, KeyboardEvent, useEffect, useState } from "react"; import { ChangeEvent, KeyboardEvent, useEffect, useState } from "react";
import { useWaku } from "@waku/react"; import { useWaku } from "@waku/react";
import { LightNode } from "@waku/interfaces"; import { LightNode } from "@waku/interfaces";
import {
TextInput,
TextComposer,
Row,
Fill,
Fit,
SendButton,
} from "@livechat/ui-kit";
interface Props { interface Props {
hasLightPushPeers: boolean; hasLightPushPeers: boolean;
@ -60,20 +52,24 @@ export default function MessageInput(props: Props) {
}, [node, inputText, hasLightPushPeers]); }, [node, inputText, hasLightPushPeers]);
return ( return (
<TextComposer <div className="flex p-2">
onKeyDown={onKeyDown} <input
type="text"
value={inputText}
onChange={onChange} onChange={onChange}
active={isActive} onKeyDown={onKeyDown}
onButtonClick={onMessage} className="flex-grow p-2 border border-gray-300 rounded-l-md"
placeholder="Type your message..."
/>
<button
onClick={onMessage}
className={`flex-none px-4 py-2 text-white ${
isActive ? "bg-blue-500" : "bg-blue-300 cursor-not-allowed"
} rounded-r-md`}
disabled={!isActive}
> >
<Row align="center"> Send
<Fill> </button>
<TextInput /> </div>
</Fill>
<Fit>
<SendButton />
</Fit>
</Row>
</TextComposer>
); );
} }

View File

@ -2,7 +2,6 @@ import type { LightNode } from "@waku/interfaces";
import ChatList from "./ChatList"; import ChatList from "./ChatList";
import MessageInput from "./MessageInput"; import MessageInput from "./MessageInput";
import { useWaku, useContentPair, useLightPush } from "@waku/react"; import { useWaku, useContentPair, useLightPush } from "@waku/react";
import { TitleBar } from "@livechat/ui-kit";
import { Message } from "./Message"; import { Message } from "./Message";
import { ChatMessage } from "./chat_message"; import { ChatMessage } from "./chat_message";
import { useNodePeers, usePeers } from "./hooks"; import { useNodePeers, usePeers } from "./hooks";
@ -49,15 +48,11 @@ export default function Room(props: Props) {
const bootstrapPeersMessage = `Bootstrap (DNS Discovery): ${bootstrapPeers.size}, Peer exchange: ${peerExchangePeers.size}. `; const bootstrapPeersMessage = `Bootstrap (DNS Discovery): ${bootstrapPeers.size}, Peer exchange: ${peerExchangePeers.size}. `;
return ( return (
<div <div className="h-screen flex flex-col">
className="chat-container" <div className="flex justify-between items-center bg-gray-800 text-white p-4">
style={{ height: "98vh", display: "flex", flexDirection: "column" }} <div>{peersMessage}</div>
> <div>{bootstrapPeersMessage} View console for more details.</div>
<TitleBar </div>
leftIcons={[peersMessage]}
rightIcons={[bootstrapPeersMessage, "View console for more details."]}
title="Waku v2 chat app"
/>
<ChatList messages={props.messages} /> <ChatList messages={props.messages} />
<MessageInput hasLightPushPeers={!!lightPushPeers} sendMessage={onSend} /> <MessageInput hasLightPushPeers={!!lightPushPeers} sendMessage={onSend} />
</div> </div>

View File

@ -1,30 +1,3 @@
@import-normalize; /* bring in normalize.css styles */ @tailwind base;
@tailwind components;
body { @tailwind utilities;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
.room-row {
text-align: left;
margin-left: 20px;
}
.room-row:after {
clear: both;
content: "";
display: table;
}
.chat-room {
margin: 2px;
}

View File

@ -1,11 +1,10 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { ThemeProvider } from "@livechat/ui-kit";
import { LightNodeProvider, ContentPairProvider } from "@waku/react"; import { LightNodeProvider, ContentPairProvider } from "@waku/react";
import { wakuDnsDiscovery, enrTree } from "@waku/dns-discovery"; import { wakuDnsDiscovery, enrTree } from "@waku/dns-discovery";
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange"; import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
import "./index.css"; import "./index.css";
import App from "./App"; import App from "./App";
import { CONTENT_TOPIC, PROTOCOLS } from "./config"; import { CONTENT_TOPIC, PROTOCOLS } from "./config";
@ -22,44 +21,13 @@ const NODE_OPTIONS = {
}, },
}; };
const THEMES = {
AuthorName: {
css: {
fontSize: "1.1em",
},
},
Message: {
css: {
margin: "0em",
padding: "0em",
fontSize: "0.83em",
},
},
MessageText: {
css: {
margin: "0em",
padding: "0.1em",
paddingLeft: "1em",
fontSize: "1.1em",
},
},
MessageGroup: {
css: {
margin: "0em",
padding: "0.2em",
},
},
};
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<ThemeProvider theme={THEMES}>
<LightNodeProvider options={NODE_OPTIONS} protocols={PROTOCOLS}> <LightNodeProvider options={NODE_OPTIONS} protocols={PROTOCOLS}>
<ContentPairProvider contentTopic={CONTENT_TOPIC}> <ContentPairProvider contentTopic={CONTENT_TOPIC}>
<App /> <App />
</ContentPairProvider> </ContentPairProvider>
</LightNodeProvider> </LightNodeProvider>
</ThemeProvider>
</React.StrictMode>, </React.StrictMode>,
document.getElementById("root") document.getElementById("root")
); );

View File

@ -1 +0,0 @@
declare module "@livechat/ui-kit";

View File

@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
};