Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect Button styling #398

Merged
merged 5 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/components/experimental_/CustomConnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { formatEther } from 'ethers/lib/utils.js';
import useBalance from '@/hooks/useBalance';
import { cleanValue } from '@/utils';
import Avatar from '../Avatar';
import { buttonStyle } from './layout/sidebar/NewChatButton';

const CustomConnectButton = () => {
const { data: balance } = useBalance();
Expand All @@ -29,9 +30,11 @@ const CustomConnectButton = () => {
(!authenticationStatus || authenticationStatus === 'authenticated');
return (
<div
className={`h-12 w-full cursor-pointer rounded-lg border-[1px] ${
!connected ? 'border-green-primary/10 bg-green-primary' : 'border-gray-800'
} bg-gray-700/50 text-center text-sm font-bold text-white hover:opacity-80`}
className={`
min-w-[200px]
cursor-pointer
hover:opacity-80
`}
{...(!ready && {
'aria-hidden': true,
style: {
Expand All @@ -44,23 +47,37 @@ const CustomConnectButton = () => {
{(() => {
if (!connected) {
return (
<button onClick={openConnectModal} type="button" className="h-full w-full p-3">
<div className="text-sm text-white/70">Connect Wallet</div>
<button onClick={openConnectModal} type="button" className="w-full">
<div
className={`flex items-center justify-center text-xs text-white/70 ${buttonStyle}`}
>
Connect Wallet
</div>
</button>
);
}

if (chain.unsupported) {
return (
<button onClick={openChainModal} type="button" className="h-full w-full p-3">
<div className="text-sm text-red-500">Wrong network</div>
<button onClick={openChainModal} type="button">
<div className="text-xs text-red-500">Wrong network</div>
</button>
);
}

return (
<div
className="flex h-full w-full cursor-pointer items-center justify-between p-3"
className="
flex h-full w-full
cursor-pointer
items-center
justify-between
rounded-lg
border-gray-800
bg-gray-600/20
p-1
px-3
"
onClick={openAccountModal}
>
<div className="flex items-center gap-3">
Expand All @@ -70,7 +87,7 @@ const CustomConnectButton = () => {
{account.displayName}
</div>
<div className="flex justify-start font-mono text-xs font-thin text-white/70">
{cleanValue(balance_, 2)}
{cleanValue(balance_, 2)} ETH
</div>
</div>
</div>
Expand Down
93 changes: 59 additions & 34 deletions src/components/experimental_/MessageInput_.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { FormEvent, ReactNode, useCallback, useEffect, useRef, useState } from 'react';
import {
FormEvent,
ReactNode,
use,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import React, { ButtonHTMLAttributes } from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { ReadyState } from 'react-use-websocket';
Expand All @@ -7,7 +16,9 @@ import {
PaperAirplaneIcon,
PaperClipIcon,
} from '@heroicons/react/24/outline';
import { useAccount } from 'wagmi';
import { useChatContext } from '@/contexts/ChatContext';
import CustomConnectButton from './CustomConnectButton';

interface IconBtnProps extends ButtonHTMLAttributes<HTMLButtonElement> {
children: ReactNode;
Expand Down Expand Up @@ -61,6 +72,8 @@ const useFocus = () => {
const MessageInput = () => {
const [messageInput, setMessageInput] = useState<string>('');

const { isConnected: walletConnected } = useAccount();

const { sendMessage, interactor, setInteractor, connectionStatus } = useChatContext();
const [inputRef] = useFocus();
const submit = useCallback(() => {
Expand All @@ -86,48 +99,60 @@ const MessageInput = () => {
setInteractor(interactor === 'user' ? 'commenter' : 'user');
};

const isConnected = connectionStatus === ReadyState.OPEN;
const botConnected = connectionStatus === ReadyState.OPEN;

const isConnected = useMemo(() => {
return walletConnected && botConnected;
}, [botConnected, walletConnected]);

return (
<div className="mx-auto w-full max-w-4xl rounded-xl bg-black/30">
<div className="flex items-center gap-1 rounded-xl border border-gray-300/10 p-1 duration-200 focus-within:border-teal-100/30 lg:gap-3 lg:p-2">
<div className="text-end">
<button
className="grid h-9 w-9 cursor-pointer select-none place-items-center rounded-lg bg-teal-200/10 align-middle text-white/70 transition duration-100 ease-in-out hover:text-white/90"
type="button"
onClick={toggleInteractionMode}
>
{interactor === 'user' ? (
<ChatBubbleLeftRightIcon className="h-5 w-5" />
) : (
<PaperClipIcon className="h-5 w-5" />
)}
</button>
</div>
<>
{isConnected ? (
<div className={`mx-auto w-full max-w-4xl rounded-xl bg-black/30 `}>
<div className="flex items-center gap-1 rounded-xl border border-gray-300/10 p-1 duration-200 focus-within:border-teal-100/30 lg:gap-3 lg:p-2">
<div className="text-end">
<button
className="grid h-9 w-9 cursor-pointer select-none place-items-center rounded-lg bg-teal-200/10 align-middle text-white/70 transition duration-100 ease-in-out hover:text-white/90"
type="button"
onClick={toggleInteractionMode}
>
{interactor === 'user' ? (
<ChatBubbleLeftRightIcon className="h-5 w-5" />
) : (
<PaperClipIcon className="h-5 w-5" />
)}
</button>
</div>

<form onSubmit={handleSendMessage} className="flex w-full grow items-center space-x-2">
<TextareaAutosize
onChange={(e) => setMessageInput(e.target.value)}
placeholder={interactor === 'user' ? 'Enter your message...' : 'Enter your comment...'}
tabIndex={0}
value={messageInput}
ref={inputRef}
onKeyDown={isConnected && messageInput ? onKeyPress : undefined}
className={`
<form onSubmit={handleSendMessage} className="flex w-full grow items-center space-x-2">
<TextareaAutosize
onChange={(e) => setMessageInput(e.target.value)}
placeholder={
interactor === 'user' ? 'Enter your message...' : 'Enter your comment...'
}
tabIndex={0}
value={messageInput}
ref={inputRef}
onKeyDown={isConnected && messageInput ? onKeyPress : undefined}
className={`
grow
resize-none
bg-transparent
tracking-wider text-white/30
placeholder:text-white/30 focus:text-white/70 focus:outline-none
`}
maxRows={7}
/>
<IconBtn onClick={handleSendMessage} disabled={!isConnected || !messageInput}>
<PaperAirplaneIcon className="h-5 w-5" />
</IconBtn>
</form>
</div>
</div>
maxRows={7}
/>
<IconBtn onClick={handleSendMessage} disabled={!isConnected || !messageInput}>
<PaperAirplaneIcon className="h-5 w-5" />
</IconBtn>
</form>
</div>
</div>
) : (
<CustomConnectButton />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If bot is not connected and wallet is connected then it's weird to show the wallet connect button?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct.. Will update that.

)}
</>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ const HeaderContainer = ({
const { pathname } = useRouter();
return (
<div
className={`sticky top-0 z-40 flex items-center gap-x-4 ${
className={`sticky top-0 z-40 flex gap-x-4 p-4 pt-6 text-white/70 sm:gap-x-6 ${
pathname !== '/' ? 'bg-gray-secondary' : ''
} p-2 text-white/70 sm:gap-x-6 md:p-6`}
}`}
>
<button type="button" className="text-white/50 lg:hidden" onClick={() => setIsOpen(!isOpen)}>
<span className="sr-only">Open sidebar</span>
<Bars3Icon className="h-8 w-8" aria-hidden="true" />
</button>

<div className="h-full w-full">{children}</div>
<div className="h-full w-full ">{children}</div>

<div className="hidden min-w-[200px] md:block">
<CustomConnectButton />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const buttonStyle =
'flex text-sm cursor-pointer select-none items-center rounded-[8px] border-[1px] border-teal-800 p-[8px] px-4 text-center text-white/70 hover:text-white transition ease-in-out hover:bg-teal-800/20 active:bg-transparent';

const NewChatButton = () => (
<Link className={buttonStyle} href={`/`}>
<Link className={`${buttonStyle} mt-4`} href={`/`}>
<div className="flex w-full justify-center text-xs">
<div>New Chat</div>
</div>
Expand Down
10 changes: 3 additions & 7 deletions src/components/experimental_/layout/sidebar/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { useContext, useState } from 'react';
import SettingsContext, { Setting } from '@/contexts/SettingsContext';
import { DevToolsModal } from '../../../devTools/DevToolsModal';
import ChatList from '../../ChatList';
import CustomConnectButton from '../../CustomConnectButton';
import AccountStatus from './AccountStatus';
import MenuButton from './MenuButton';
import MoreItems from './MoreItems';
import NewChatButton from './NewChatButton';

Expand All @@ -21,23 +19,21 @@ const Sidebar = ({
} = useContext(SettingsContext);

return (
<div className="flex h-screen w-full flex-1 flex-col p-1.5 text-gray-300">
<div className="flex h-screen w-full flex-col gap-2 p-2 text-gray-300">
<DevToolsModal
openState={developerTools}
handleClose={() => changeSetting(Setting.DEVELOPER_TOOLS, false)}
/>
<NewChatButton />
<div className="h-full overflow-y-auto">
<div className="h-full overflow-y-scroll ">
<ChatList />
</div>
<div className="relative flex w-full flex-col self-end">
<div className="p-1.5">
<div className="p-2">
<MoreItems />
{/* {process.env.NODE_ENV === 'development' && <AccountStatus />} */}
<div className="p-2">
<AccountStatus />
</div>
{/* <div className="text-xs text-white/50 border-[0.5px] rounded-xl p-1 ">App version: v{process.env.APP_VERSION}</div> */}
</div>
</div>
</div>
Expand Down