Skip to content

Commit 36f6d26

Browse files
committed
Completed video editor studio 🌟✅✅
1 parent 088588b commit 36f6d26

File tree

5 files changed

+296
-173
lines changed

5 files changed

+296
-173
lines changed

components/Sidebar.jsx

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { useRouter } from "next/router";
2+
import { useEffect, useState } from "react";
3+
import { useChannelState } from "../context/ChannelState";
24
import { useStateContext } from "../context/StateContext";
35

46
const Sidebar = () => {
@@ -9,11 +11,17 @@ const Sidebar = () => {
911
setLoadingProgress,
1012
activeSidebar,
1113
setActiveSidebar,
12-
subscriptions,
1314
activeSubscription,
1415
setActiveSubscription,
1516
} = useStateContext();
1617
const router = useRouter();
18+
const { currentChannel, fetchChannelDetails, GetUid, startLoadingBar } = useChannelState();
19+
const [subscriptions, setSubscriptions] = useState();
20+
21+
useEffect(() => {
22+
setSubscriptions(currentChannel?.subscriptions);
23+
console.log(currentChannel);
24+
}, []);
1725

1826
return (
1927
<div
@@ -68,44 +76,49 @@ const Sidebar = () => {
6876
<h2 className="dark:text-white ext-sl m-2">Subscriptions</h2>
6977
)}
7078
<div>
71-
{subscriptions?.map((subscription) => (
79+
{subscriptions?.map((channelRef) => (
7280
<div
7381
onClick={() => {
74-
setLoading(true);
75-
setLoadingProgress(60);
76-
setTimeout(() => {
77-
setLoadingProgress(100);
78-
setActiveSubscription(subscription.channelDisplayName);
79-
router.push(`/${subscription.channelName}`);
80-
}, 500);
81-
82-
setTimeout(() => {
83-
setLoading(false);
84-
}, 800);
82+
startLoadingBar(
83+
setLoading,
84+
setLoadingProgress,
85+
() =>
86+
setActiveSubscription(
87+
fetchChannelDetails(channelRef)?.channelDisplayName
88+
)
89+
);
90+
91+
router.push(
92+
`/${
93+
fetchChannelDetails(channelRef)?.channelDisplayName
94+
}`
95+
)
8596
}}
8697
className={`${
8798
isSidebar ? "rounded-lg" : "rounded-full"
8899
} flex dark:hover:bg-white/20 items-center cursor-pointer transition my-2 hover:bg-gray-100 active:bg-gray-200 ${
89-
activeSubscription === subscription.channelName &&
100+
activeSubscription ===
101+
fetchChannelDetails(channelRef)?.channelName &&
90102
"bg-gray-100 dark:bg-white/10 dark:active:bg-white/30"
91103
}`}
92-
key={subscription.channelName}
104+
key={GetUid()}
93105
>
94106
<span className="1/3">
95107
<img
96-
src={subscription.channelImage}
108+
src={fetchChannelDetails(channelRef)?.channelImage}
97109
className="icon"
98110
alt="profile picture"
99111
/>
100112
</span>
101113
{isSidebar && (
102114
<span
103115
className={`text-sm text-gray-900 dark:text-white ${
104-
activeSubscription === subscription.channelName &&
116+
activeSubscription ===
117+
fetchChannelDetails(channelRef)?.channelName &&
105118
"font-semibold text-black dark:text-white"
106119
}`}
107120
>
108-
{subscription.channelDisplayName}
121+
{fetchChannelDetails(channelRef)?.channelDisplayName}
109122
</span>
110123
)}
111124
</div>

0 commit comments

Comments
 (0)