-
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.
Fix state management and bugs in pages
- Loading branch information
Showing
9 changed files
with
248 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import styled from "styled-components"; | ||
import VideoCard from "../components/VideoCard"; | ||
import axios from "axios"; | ||
import {IVideo} from "../utils/types" | ||
import SearchBar from "../components/SearchBar" | ||
import useStore from "../store"; | ||
|
||
const Container = styled.div` | ||
padding: 2em; | ||
display: flex; | ||
justify-content: space-between; | ||
flex-wrap: wrap; | ||
`; | ||
|
||
const HistoryPage = () => { | ||
const store = useStore(); | ||
const user = store.authUser; | ||
const [videos, setVideos] = useState([]); | ||
|
||
useEffect(() => { | ||
const SERVER_ENDPOINT = import.meta.env.VITE_BACKEND_ENDPOINT; | ||
const fetchVideos = async () => { | ||
const res = await axios.get(`${SERVER_ENDPOINT}/users/${user?._id}/history`, {withCredentials: true}); | ||
setVideos(res.data); | ||
}; | ||
fetchVideos(); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<SearchBar /> | ||
<Container> | ||
{videos.map((video: IVideo) => ( | ||
<VideoCard key={video._id} type={null} video={video}/> | ||
))} | ||
</Container> | ||
</> | ||
); | ||
}; | ||
|
||
export default HistoryPage; |
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import styled from "styled-components"; | ||
import ChannelCard from "../components/ChannelCard"; | ||
import axios from "axios"; | ||
import {IChannel} from "../utils/types" | ||
import SearchBar from "../components/SearchBar" | ||
import useStore from "../store"; | ||
|
||
const Container = styled.div` | ||
padding: 2em; | ||
display: flex; | ||
justify-content: space-between; | ||
flex-wrap: wrap; | ||
`; | ||
|
||
const SubscriptionsPage = () => { | ||
const store = useStore(); | ||
const user = store.authUser; | ||
const [channels, setChannels] = useState([]); | ||
|
||
useEffect(() => { | ||
const SERVER_ENDPOINT = import.meta.env.VITE_BACKEND_ENDPOINT; | ||
const fetchVideos = async () => { | ||
const res = await axios.get(`${SERVER_ENDPOINT}/users/${user?._id}/subscriptions`, {withCredentials: true}); | ||
setChannels(res.data); | ||
}; | ||
fetchVideos(); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<SearchBar /> | ||
<Container> | ||
{channels.map((channel: IChannel) => ( | ||
<ChannelCard key={channel._id} channel={channel}/> | ||
))} | ||
</Container> | ||
</> | ||
); | ||
}; | ||
|
||
export default SubscriptionsPage; |
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
Oops, something went wrong.