generated from hatchways/express-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from hatchways/reorder-switch
Reorder switch
- Loading branch information
Showing
4 changed files
with
109 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useContext, useEffect } from "react"; | ||
import InfiniteScroll from "react-infinite-scroller"; | ||
import { UserContext } from "../context/user"; | ||
import { getMentions } from "../hooks/getMentions"; | ||
import Spinner from "./Spinner"; | ||
import Mention from "../layout/Mention"; | ||
|
||
const Scroller = ({ | ||
sort, | ||
error, | ||
loadmore, | ||
hasMore, | ||
setHasMore, | ||
mentionDatas, | ||
setMentionDatas, | ||
}) => { | ||
const { dispatch, searchTerm, user } = useContext(UserContext); | ||
|
||
useEffect(() => { | ||
getMentions(dispatch, searchTerm, user.platforms, 1, sort) | ||
.then((data) => { | ||
setMentionDatas(data.mentions); | ||
setHasMore(data.nextPage ? true : false); | ||
}) | ||
.catch((err) => alert("Cookie expired. Please log in again")); | ||
}, [sort]); | ||
|
||
return ( | ||
<InfiniteScroll | ||
pageStart={1} | ||
loadMore={loadmore} | ||
hasMore={hasMore} | ||
loader={<Spinner />}> | ||
{!error && mentionDatas.length > 0 ? ( | ||
mentionDatas.map((mentionData) => ( | ||
<Mention key={mentionData._id} mention={mentionData} /> | ||
)) | ||
) : ( | ||
<div>No results found</div> | ||
)} | ||
</InfiniteScroll> | ||
); | ||
}; | ||
|
||
export default Scroller; |
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,22 @@ | ||
import React from "react"; | ||
import ToggleButton from "@material-ui/lab/ToggleButton"; | ||
import ToggleButtonGroup from "@material-ui/lab/ToggleButtonGroup"; | ||
|
||
const SortToggle = ({ handleAlignment, alignment }) => { | ||
return ( | ||
<ToggleButtonGroup | ||
value={alignment} | ||
exclusive | ||
onChange={handleAlignment} | ||
aria-label="text alignment"> | ||
<ToggleButton value="date" aria-label="left aligned"> | ||
Most Recent | ||
</ToggleButton> | ||
<ToggleButton value="popularity" aria-label="right aligned"> | ||
Most Popular | ||
</ToggleButton> | ||
</ToggleButtonGroup> | ||
); | ||
}; | ||
|
||
export default SortToggle; |
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