Skip to content

Commit

Permalink
Merge pull request #11 from guicoelhodev/develop
Browse files Browse the repository at this point in the history
Fix chat style errors and increase user experience in mobile devices
  • Loading branch information
guicoelhodev authored Jan 2, 2023
2 parents b26a15d + 2774acb commit 3777ba7
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 31 deletions.
8 changes: 6 additions & 2 deletions src/components/FC/Chat/CurrentChat/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export const Container = styled(motion.div)`
align-content: space-between;
@media (max-width: 500px) {
grid-template-rows: 2rem calc(50vh - 5rem) 3rem;
grid-template-rows: 2rem calc(40rem) 3rem;
footer {
padding-bottom: 0;
}
}
`;

Expand Down Expand Up @@ -75,7 +79,7 @@ export const SendContainer = styled.footer`
gap: 0.4rem;
input {
border-color: ${(props) => props.theme.terciaryColor};
border: 1px solid ${(props) => props.theme.terciaryColor};
flex: 1;
width: 100%;
background-color: ${(props) => props.theme.primaryBg};
Expand Down
11 changes: 9 additions & 2 deletions src/components/FC/Chat/SearchFriends/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ export const List = styled.ul`
align-items: flex-start;
justify-content: center;
grid-template-columns: repeat(auto-fit, 3rem);
grid-template-columns: repeat(3, 3rem);
justify-content: space-evenly;
grid-template-rows: repeat(auto-fit, 3rem);
gap: 1rem;
overflow-y: auto;
padding-top: 1rem;
@media (max-width: 500px) {
height: calc(50vh);
height: 42rem;
grid-template-columns: repeat(3, 4rem);
grid-template-rows: repeat(auto-fit, 4rem);
button {
width: 4rem;
}
}
`;
17 changes: 11 additions & 6 deletions src/components/FC/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useContext, useState } from 'react';
import { AiOutlineSearch } from 'react-icons/ai';
import { BsChevronUp } from 'react-icons/bs';
import { BiUserVoice } from 'react-icons/bi';
Expand All @@ -8,27 +8,32 @@ import { CurrentChat } from './CurrentChat';
import { SearchFriends } from './SearchFriends';
import { listFriendsActiveMock } from './tmpMocks';

import { UserActionsContext } from '@context/userActions';
import { handleChatState } from 'src/reducers/globalComponentsReducer/actions';

import * as S from './style';

export const Chat: React.FC = () => {
const [open, setOpen] = useState(false);
const { globalComponentsState, dispatchGlobalComponents } =
useContext(UserActionsContext);
const [searchFriends, setSearchFriends] = useState(false);

return (
<S.Container
variants={chatTransition}
animate={open ? 'open' : 'closed'}
animate={globalComponentsState?.chat ? 'open' : 'closed'}
transition={{ duration: 0.2, ease: 'easeIn' }}
open={globalComponentsState.chat}
>
<S.Header open={open}>
<S.Header open={globalComponentsState.chat}>
<p>Chat</p>

<button onClick={() => setOpen((prev) => !prev)}>
<button onClick={() => dispatchGlobalComponents(handleChatState())}>
<BsChevronUp />
</button>
</S.Header>

{open ? (
{globalComponentsState.chat ? (
<S.Content>
{searchFriends ? <SearchFriends /> : <CurrentChat />}

Expand Down
14 changes: 8 additions & 6 deletions src/components/FC/Chat/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import styled from 'styled-components';
interface IChatState {
open: boolean;
}
export const Container = styled(motion.section)`

export const Container = styled(motion.section)<IChatState>`
z-index: 2;
position: fixed;
bottom: 0;
right: 6rem;
overflow: hidden;
background-color: ${(props) => props.theme.secondaryBg};
Expand All @@ -21,17 +21,19 @@ export const Container = styled(motion.section)`
flex-direction: column;
border: 1px solid ${(props) => props.theme.primaryColor};
border-bottom-color: inherit;
border-bottom-color: ${(props) => props.theme.secondaryBg};
@media (max-width: 810px) {
bottom: 5rem;
display: ${(props) => (props.open ? 'block' : 'none !important')};
bottom: 4rem;
right: 0;
}
@media (max-width: 500px) {
border: 0;
max-width: none;
max-height: 60vh;
border-color: inherit;
max-height: 50rem;
border-color: ${(props) => props.theme.primaryBg};
border-radius: 0;
}
`;
Expand Down
13 changes: 11 additions & 2 deletions src/components/UI/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ import {
AiOutlineUsergroupAdd,
} from 'react-icons/ai';
import { useRouter } from 'next/router';
import { UserActionsContext } from '@context/userActions';
import { handleChatState } from 'src/reducers/globalComponentsReducer/actions';

interface ILayout {
children: ReactNode;
}

export const Layout: React.FC<ILayout> = ({ children }) => {
const { theme, themeToggler } = useContext(ThemeContext);
const { globalComponentsState, dispatchGlobalComponents } =
useContext(UserActionsContext);

const router = useRouter();

Expand Down Expand Up @@ -57,10 +61,15 @@ export const Layout: React.FC<ILayout> = ({ children }) => {
{
title: 'Chat',
icon: <BsFillChatDotsFill />,
onClick: () => alert('clicked '),
onClick: () => dispatchGlobalComponents(handleChatState()),
},
];

const getActiveClassName = (title: string) => {
if (title === 'Chat') return globalComponentsState.chat ? 'active' : '';
return title === activeTab ? 'active' : '';
};

return (
<S.Container>
<S.Header>
Expand All @@ -80,7 +89,7 @@ export const Layout: React.FC<ILayout> = ({ children }) => {
item.onClick();
}}
title={item.title}
className={item.title === activeTab ? 'active' : ''}
className={getActiveClassName(item.title)}
>
{item.icon}

Expand Down
5 changes: 4 additions & 1 deletion src/components/UI/Layout/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const PageContainer = styled.div`
}
`;
export const NavigatePages = styled.nav`
z-index: 3;
background-color: ${(props) => props.theme.primaryBg};
padding-top: 2rem;
position: fixed;
Expand All @@ -47,7 +48,9 @@ export const NavigatePages = styled.nav`
}
@media (max-width: 810px) {
top: calc(var(--doc-height) - 4rem);
background-color: ${(props) => props.theme.secondaryBg};
bottom: 0;
position: sticky;
width: 100%;
height: 4rem;
padding: 0;
Expand Down
42 changes: 33 additions & 9 deletions src/context/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import { FC, ReactNode } from 'react';
import React, { ReactNode } from 'react';
import { ThemeContextProvider } from './theme';
import { UserActionsProvider } from './userActions';
interface MultiProviderProps {
children: ReactNode;
}

const providers = [ThemeContextProvider, UserActionsProvider];

interface IGlobalContext {
export const MultiProvider: React.FC<MultiProviderProps> = ({ children }) => (
<>
{providers.reduceRight((acc, Comp) => {
return <Comp>{acc}</Comp>;
}, children)}
</>
);

/*
If you want to add provider by props:
interface MultiProviderProps {
providers: Array<React.JSXElementConstructor<React.PropsWithChildren<unknown>>
>;
children: ReactNode;
}
export const GlobalProvider: FC<IGlobalContext> = ({ children }) => {
return (
<>
<ThemeContextProvider>{children}</ThemeContextProvider>
</>
);
};
export const MultiProvider: React.FC<MultiProviderProps> = ({
providers = [],
children,
}) => (
<>
{providers.reduceRight((acc, Comp) => {
return <Comp>{acc}</Comp>;
}, children)}
</>
);
*/
37 changes: 37 additions & 0 deletions src/context/userActions/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createContext, FC, ReactNode, useReducer } from 'react';
import { globalComponentsReducer } from 'src/reducers/globalComponentsReducer/reducer';

export type IGlobalComponents = {
chat: boolean;
createPost: boolean;
addFriend: boolean;
};
type IUserActionsContext = {
globalComponentsState: any;
dispatchGlobalComponents: any;
};

interface IUserActionsProvider {
children: ReactNode;
}

export const UserActionsContext = createContext<IUserActionsContext>(null!);

export const UserActionsProvider: FC<IUserActionsProvider> = ({ children }) => {
const [globalComponentsState, dispatchGlobalComponents] = useReducer<any>(
globalComponentsReducer,
{
addFriend: false,
chat: false,
createPost: false,
}
);

return (
<UserActionsContext.Provider
value={{ globalComponentsState, dispatchGlobalComponents }}
>
{children}
</UserActionsContext.Provider>
);
};
6 changes: 3 additions & 3 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AppProps } from 'next/app';
import { GlobalProvider } from '../context';
import { MultiProvider } from '../context';
import { SessionProvider } from 'next-auth/react';
import { GlobalStyles } from '@style/globalStyle';
import { AuthComponent } from 'src/global/auth/AuthComponent';
Expand All @@ -18,7 +18,7 @@ export default function App({
getHeightPhone();
return (
<QueryClientProvider client={queryClient}>
<GlobalProvider>
<MultiProvider>
<SessionProvider session={session}>
<GlobalStyles />

Expand All @@ -30,7 +30,7 @@ export default function App({
<Component {...pageProps} />
)}
</SessionProvider>
</GlobalProvider>
</MultiProvider>
</QueryClientProvider>
);
}
17 changes: 17 additions & 0 deletions src/reducers/globalComponentsReducer/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export enum ActionsGlobalComponents {
HANDLE_CHAT_STATE = 'HANDLE_CHAT_STATE',
HANDLE_CREATE_POST = 'HANDLE_CREATE_POST',
HANDLE_ADD_FRIEND = 'HANDLE_ADD_FRIEND',
}

export const handleChatState = () => {
return { type: ActionsGlobalComponents.HANDLE_CHAT_STATE };
};

export const handleCreatPostState = () => {
return { type: ActionsGlobalComponents.HANDLE_CREATE_POST };
};

export const handleAddFriend = () => {
return { type: ActionsGlobalComponents.HANDLE_ADD_FRIEND };
};
21 changes: 21 additions & 0 deletions src/reducers/globalComponentsReducer/reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IGlobalComponents } from '@context/userActions';
import { ActionsGlobalComponents } from './actions';

export const globalComponentsReducer = (
state: IGlobalComponents,
action: { type: string }
) => {
switch (action.type) {
case ActionsGlobalComponents.HANDLE_CHAT_STATE: {
return { ...state, chat: !state.chat };
}
case ActionsGlobalComponents.HANDLE_CREATE_POST: {
return { ...state, createPost: !state.createPost };
}
case ActionsGlobalComponents.HANDLE_ADD_FRIEND: {
return { ...state, addFriend: !state.addFriend };
}
default:
state;
}
};

1 comment on commit 3777ba7

@vercel
Copy link

@vercel vercel bot commented on 3777ba7 Jan 2, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.