Skip to content

Commit

Permalink
Step 11.5: Add sign-out button that ChatsNavbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Urigo committed May 20, 2020
1 parent a1b1953 commit 8008d81
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
38 changes: 36 additions & 2 deletions src/components/ChatsListScreen/ChatsNavbar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
import React from 'react';
import { Toolbar } from '@material-ui/core';
import { Button, Toolbar } from '@material-ui/core';
import styled from 'styled-components';
import SignOutIcon from '@material-ui/icons/PowerSettingsNew';
import { useCallback } from 'react';
import { useSignOut } from '../../services/auth.service';
import { History } from 'history';

const Container = styled(Toolbar)`
display: flex;
background-color: var(--primary-bg);
color: var(--primary-text);
font-size: 20px;
line-height: 40px;
`;

const ChatsNavbar: React.FC = () => <Container>Whatsapp Clone</Container>;
const Title = styled.div`
flex: 1;
`;

const LogoutButton = styled(Button)`
color: var(--primary-text) !important;
`;

interface ChildComponentProps {
history: History;
}

const ChatsNavbar: React.FC<ChildComponentProps> = ({ history }) => {
const signOut = useSignOut();

const handleSignOut = useCallback(() => {
signOut().then(() => {
history.replace('/sign-in');
});
}, [history, signOut]);

return (
<Container>
<Title>Whatsapp Clone</Title>
<LogoutButton data-testid="sign-out-button" onClick={handleSignOut}>
<SignOutIcon />
</LogoutButton>
</Container>
);
};

export default ChatsNavbar;
2 changes: 1 addition & 1 deletion src/components/ChatsListScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface ChatsListScreenProps {

const ChatsListScreen: React.FC<ChatsListScreenProps> = ({ history }) => (
<Container>
<ChatsNavbar />
<ChatsNavbar history={history} />
<ChatsList history={history} />
</Container>
);
Expand Down

0 comments on commit 8008d81

Please sign in to comment.