1
1
import { useRouter } from "next/router" ;
2
+ import { useEffect , useState } from "react" ;
3
+ import { useChannelState } from "../context/ChannelState" ;
2
4
import { useStateContext } from "../context/StateContext" ;
3
5
4
6
const Sidebar = ( ) => {
@@ -9,11 +11,17 @@ const Sidebar = () => {
9
11
setLoadingProgress,
10
12
activeSidebar,
11
13
setActiveSidebar,
12
- subscriptions,
13
14
activeSubscription,
14
15
setActiveSubscription,
15
16
} = useStateContext ( ) ;
16
17
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
+ } , [ ] ) ;
17
25
18
26
return (
19
27
< div
@@ -68,44 +76,49 @@ const Sidebar = () => {
68
76
< h2 className = "dark:text-white ext-sl m-2" > Subscriptions</ h2 >
69
77
) }
70
78
< div >
71
- { subscriptions ?. map ( ( subscription ) => (
79
+ { subscriptions ?. map ( ( channelRef ) => (
72
80
< div
73
81
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
+ )
85
96
} }
86
97
className = { `${
87
98
isSidebar ? "rounded-lg" : "rounded-full"
88
99
} 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 &&
90
102
"bg-gray-100 dark:bg-white/10 dark:active:bg-white/30"
91
103
} `}
92
- key = { subscription . channelName }
104
+ key = { GetUid ( ) }
93
105
>
94
106
< span className = "1/3" >
95
107
< img
96
- src = { subscription . channelImage }
108
+ src = { fetchChannelDetails ( channelRef ) ? .channelImage }
97
109
className = "icon"
98
110
alt = "profile picture"
99
111
/>
100
112
</ span >
101
113
{ isSidebar && (
102
114
< span
103
115
className = { `text-sm text-gray-900 dark:text-white ${
104
- activeSubscription === subscription . channelName &&
116
+ activeSubscription ===
117
+ fetchChannelDetails ( channelRef ) ?. channelName &&
105
118
"font-semibold text-black dark:text-white"
106
119
} `}
107
120
>
108
- { subscription . channelDisplayName }
121
+ { fetchChannelDetails ( channelRef ) ? .channelDisplayName }
109
122
</ span >
110
123
) }
111
124
</ div >
0 commit comments