added styles and api route symlink

This commit is contained in:
J Taylor 2021-06-23 15:41:51 +01:00
parent d7e963b1ec
commit ca3e773a5c
6 changed files with 119 additions and 23 deletions

View File

@ -22,6 +22,8 @@ export const Aside = ({ onClose, children }) => (
.call-aside { .call-aside {
background: white; background: white;
position: relative; position: relative;
flex-shrink: 0;
flex-grow: 0;
width: ${ASIDE_WIDTH}px; width: ${ASIDE_WIDTH}px;
height: 100vh; height: 100vh;
box-sizing: border-box; box-sizing: border-box;
@ -32,6 +34,9 @@ export const Aside = ({ onClose, children }) => (
.call-aside .inner { .call-aside .inner {
overflow-x: hidden; overflow-x: hidden;
overflow-y: scroll; overflow-y: scroll;
height: 100%;
display: flex;
flex-flow: column wrap;
} }
.call-aside .close { .call-aside .close {

View File

@ -242,6 +242,19 @@ export const Button = forwardRef(
background: ${hexa(theme.blue.light, 1)}; background: ${hexa(theme.blue.light, 1)};
} }
.button.transparent {
background: transparent;
color: var(--primary-default);
border: 0px;
}
.button.transparent:hover,
.button.transparent:focus,
.button.transparent:active {
border: 0px;
box-shadow: none;
color: var(--primary-dark);
}
.button.blur { .button.blur {
background: ${hexa(theme.blue.default, 0.35)}; background: ${hexa(theme.blue.default, 0.35)};
backdrop-filter: blur(10px); backdrop-filter: blur(10px);

View File

@ -120,6 +120,12 @@ const InputContainer = ({ children, prefix, className }) => (
color: var(--text-mid); color: var(--text-mid);
opacity: 1; opacity: 1;
} }
.transparent :global(input) {
background: transparent;
border: 0px;
box-shadow: none;
}
`}</style> `}</style>
</div> </div>
); );

View File

@ -1,5 +1,7 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import Aside from '@dailyjs/shared/components/Aside'; import Aside from '@dailyjs/shared/components/Aside';
import { Button } from '@dailyjs/shared/components/Button';
import { TextInput } from '@dailyjs/shared/components/Input';
import { useUIState } from '@dailyjs/shared/contexts/UIStateProvider'; import { useUIState } from '@dailyjs/shared/contexts/UIStateProvider';
import { useChat } from '../../contexts/ChatProvider'; import { useChat } from '../../contexts/ChatProvider';
@ -9,6 +11,7 @@ export const ChatAside = () => {
const { showAside, setShowAside } = useUIState(); const { showAside, setShowAside } = useUIState();
const { sendMessage, chatHistory, setHasNewMessages } = useChat(); const { sendMessage, chatHistory, setHasNewMessages } = useChat();
const [newMessage, setNewMessage] = useState(''); const [newMessage, setNewMessage] = useState('');
const chatWindowRef = useRef();
useEffect(() => { useEffect(() => {
// Clear out any new message otifications if we're showing the chat screen // Clear out any new message otifications if we're showing the chat screen
@ -17,33 +20,101 @@ export const ChatAside = () => {
} }
}, [showAside, chatHistory.length, setHasNewMessages]); }, [showAside, chatHistory.length, setHasNewMessages]);
useEffect(() => {
if (chatWindowRef.current) {
chatWindowRef.current.scrollTop = chatWindowRef.current.scrollHeight;
}
}, [chatHistory?.length]);
if (!showAside || showAside !== CHAT_ASIDE) { if (!showAside || showAside !== CHAT_ASIDE) {
return null; return null;
} }
return ( return (
<Aside onClose={() => setShowAside(false)}> <Aside onClose={() => setShowAside(false)}>
{chatHistory.map((chatItem) => ( <div className="messages-container" ref={chatWindowRef}>
<div key={chatItem.id}> {chatHistory.map((chatItem) => (
{chatItem.sender} - {chatItem.message} <div
</div> className={chatItem.isLocal ? 'message local' : 'message'}
))} key={chatItem.id}
<hr /> >
<input <span className="content">{chatItem.message}</span>
type="text" <span className="sender">{chatItem.sender}</span>
value={newMessage} </div>
onChange={(e) => setNewMessage(e.target.value)} ))}
/> </div>
<button <footer className="chat-footer">
type="button" <TextInput
disabled={!newMessage} value={newMessage}
onClick={() => { placeholder="Type message here"
sendMessage(newMessage); variant="transparent"
setNewMessage(''); onChange={(e) => setNewMessage(e.target.value)}
}} />
> <Button
Send a test message className="send-button"
</button> variant="transparent"
disabled={!newMessage}
onClick={() => {
sendMessage(newMessage);
setNewMessage('');
}}
>
Send
</Button>
</footer>
<style jsx>{`
.messages-container {
flex: 1;
overflow-y: scroll;
}
.message {
margin: var(--spacing-xxs);
padding: var(--spacing-xxs);
background: var(--gray-wash);
border-radius: var(--radius-sm);
font-size: 0.875rem;
}
.message.local {
background: var(--gray-light);
}
.message.local .sender {
color: var(--primary-default);
}
.content {
color: var(--text-mid);
display: block;
}
.sender {
font-weight: var(--weight-medium);
font-size: 0.75rem;
}
.chat-footer {
flex-flow: row nowrap;
box-sizing: border-box;
padding: var(--spacing-xxs) 0;
display: flex;
position: relative;
border-top: 1px solid var(--gray-light);
}
.chat-footer :global(.input-container) {
flex: 1;
}
.chat-footer :global(.input-container input) {
padding-right: 0px;
}
.chat-footer :global(.send-button) {
padding: 0 var(--spacing-xs);
}
`}</style>
</Aside> </Aside>
); );
}; };

View File

@ -53,7 +53,7 @@ export const ChatProvider = ({ children }) => {
// Update local chat history // Update local chat history
return setChatHistory((oldState) => [ return setChatHistory((oldState) => [
...oldState, ...oldState,
{ sender, message, id: nanoid() }, { sender, message, id: nanoid(), isLocal: true },
]); ]);
}, },
[callObject] [callObject]

1
dailyjs/text-chat/pages/api Symbolic link
View File

@ -0,0 +1 @@
basic-call/pages/api