-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65bc0f6
commit 46174e9
Showing
5 changed files
with
152 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,41 @@ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import { Box, Button, Container, styled, Typography } from '@mui/material'; | ||
import { useNavigate } from 'react-router-dom'; | ||
// import StoryControlPanel from './StoryControlPanel'; | ||
import { dashboardCss, newStoryBtnCss, controlSectionCss, storiesSectionCss, welcomeTextCss, instructionsTextCss } from '../../../styles/homePageCss'; | ||
import React, { useContext } from 'react'; | ||
import { UserContext } from '../../../context/UserContext'; | ||
import { Container, IconButton, Tooltip, Zoom, styled } from '@mui/material'; | ||
import { dashboardCss, logoutBtn } from '../../../styles/homePageCss'; | ||
import Bookshelf from './Bookshelf'; | ||
import Welcome from './Welcome'; | ||
import LogoutIcon from '@mui/icons-material/Logout'; | ||
import { handleDELETE } from '../../../helpers/fetchRequests'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const HomePage = () => { | ||
const [bookshelfStories, setBookshelfStories] = useState([]); | ||
const [allStories, setAllStories] = useState([]); | ||
const [noStories, setNoStories] = useState(false); | ||
const [url, setUrl] = useState('/stories'); | ||
const { user } = useContext(UserContext); | ||
const { setUser } = useContext(UserContext); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
fetch(url).then((res) => { | ||
res.json().then((stories) => { | ||
if (stories.length > 0) { | ||
setNoStories(false); | ||
setAllStories(stories); | ||
setBookshelfStories(stories); | ||
} else { | ||
setNoStories(true); | ||
} | ||
}) | ||
}) | ||
}, [url]); | ||
|
||
const handleUpdateStories = (stories) => { | ||
if (stories.length === 0) { | ||
setNoStories(true); | ||
} else { | ||
setNoStories(false); | ||
setBookshelfStories(stories); | ||
} | ||
}; | ||
|
||
const handleUpdateUrl = (newUrl) => { | ||
setUrl(newUrl); | ||
const handleLogout = () => { | ||
handleDELETE('/logout') | ||
.then(() => setUser(null)) | ||
.then(navigate('/')); | ||
}; | ||
|
||
return ( | ||
<Dashboard> | ||
<ControlSection> | ||
<WelcomeText>Welcome to Storyteller, {user.username}!</WelcomeText> | ||
<InstructionsText>Choose a story from the Bookshelf, and pick up where the previous author left off. Or, being writing a new one to share with other authors.</InstructionsText> | ||
<NewStoryBtn | ||
variant="contained" | ||
onClick={ () => navigate('/story/new') } | ||
> | ||
Create a New Story Here | ||
</NewStoryBtn> | ||
{/* <StoryControlPanel | ||
allStories={ allStories } | ||
bookshelfStories={ bookshelfStories } | ||
noStories={ noStories } | ||
onUpdateStories={ handleUpdateStories } | ||
onUpdateUrl={ handleUpdateUrl } | ||
/> */} | ||
</ControlSection> | ||
<StoriesSection> | ||
<Bookshelf | ||
allStories={ allStories } | ||
onUpdateStories={ handleUpdateStories } | ||
onUpdateUrl={ handleUpdateUrl } | ||
bookshelfStories={ bookshelfStories } | ||
noStories={ noStories } | ||
/> | ||
</StoriesSection> | ||
<Welcome /> | ||
<Bookshelf /> | ||
<Tooltip | ||
title={`LOGOUT`} | ||
placement="bottom" | ||
TransitionComponent={Zoom} | ||
> | ||
<LogoutBtn onClick={ () => handleLogout() } > | ||
<LogoutIcon /> | ||
</LogoutBtn> | ||
</Tooltip> | ||
</Dashboard> | ||
) | ||
} | ||
|
||
export default HomePage | ||
|
||
const Dashboard = styled(Container)(dashboardCss); | ||
const ControlSection = styled(Box)(controlSectionCss); | ||
const WelcomeText = styled(Typography)(welcomeTextCss); | ||
const InstructionsText = styled(Typography)(instructionsTextCss); | ||
const StoriesSection = styled(Box)(storiesSectionCss); | ||
const NewStoryBtn = styled(Button)(newStoryBtnCss); | ||
const LogoutBtn = styled(IconButton)(logoutBtn); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useContext } from 'react'; | ||
import { newStoryBtnCss, welcomeTextCss, instructionsTextCss, welcomeSectionCss } from '../../../styles/homePageCss'; | ||
import { Box, Button, styled, Typography } from '@mui/material'; | ||
import { UserContext } from '../../../context/UserContext'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const Welcome = () => { | ||
const { user } = useContext(UserContext); | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<> | ||
<WelcomeSection> | ||
<WelcomeText>Welcome to STORYTELLER, {user.username}!</WelcomeText> | ||
<InstructionsText>Choose a story below, or create a new one.</InstructionsText> | ||
<NewStoryBtn | ||
variant="contained" | ||
onClick={ () => navigate('/story/new') } | ||
> | ||
Create New Story | ||
</NewStoryBtn> | ||
</WelcomeSection> | ||
</> | ||
) | ||
} | ||
|
||
export default Welcome | ||
|
||
|
||
const WelcomeSection = styled(Box)(welcomeSectionCss); | ||
const WelcomeText = styled(Typography)(welcomeTextCss); | ||
const InstructionsText = styled(Typography)(instructionsTextCss); | ||
const NewStoryBtn = styled(Button)(newStoryBtnCss); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters