1
1
import { useContext , createContext , useState } from "react" ;
2
2
import { async } from "regenerator-runtime" ;
3
+ import { uid } from "uid" ;
3
4
import UIDGenerator from "uid-generator" ;
4
5
import { supabase } from "../SupabaseClient" ;
5
6
export const ChannelState = createContext ( ) ;
@@ -11,53 +12,6 @@ export const ChannelStateProvider = ({ children }) => {
11
12
const [ commentOption , setCommentOption ] = useState ( "" ) ;
12
13
const [ likedVideos , setLikedVideos ] = useState ( [ ] ) ;
13
14
14
- // deffault channel
15
- /*
16
- {
17
- channelName: "Gaurav",
18
- channelImage: "https://avatars.githubusercontent.com/u/88154142?v=4",
19
- channelBannerImage:
20
- "https://cdn.pixabay.com/photo/2017/10/31/19/05/web-design-2906159__480.jpg",
21
- subscribers: 1301310301,
22
- uid: "a00c3e26-aa9b-11fa-afa1-0242ac120003",
23
- channelDisplayName: "Gaurav",
24
- socialLinks: [
25
- {
26
- name: "facebook",
27
- logo: "https://cdn-icons-png.flaticon.com/128/5968/5968764.png",
28
- url: "http://www.facebook.com",
29
- },
30
- {
31
- name: "instagram",
32
- logo: "https://cdn-icons-png.flaticon.com/128/174/174855.png",
33
- url: "http://www.instagram.com",
34
- },
35
- {
36
- name: "twitter",
37
- logo: "https://cdn-icons-png.flaticon.com/128/733/733579.png",
38
- url: "http://www.twitter.com",
39
- },
40
- ],
41
- views: 23242323232323,
42
- joinedDate: new Date(),
43
- description: `This is my brand new Channel`,
44
- location: "United States",
45
- subscriptions: [
46
- "a20c3a26-aa9b-11wa-afa1-0442ac120009",
47
- "a00c3e26-aa9b-11ed-afa1-0242ac120002",
48
- ],
49
- email: "gaurav@gmail.com",
50
- playlists: [
51
- {
52
- name: "MyPlaylist",
53
- videos: [],
54
- }, {
55
- name: "My Playlist 2 ",
56
- videos: ["449112141"],
57
- },
58
- ],
59
- }*/
60
-
61
15
const [ News , setNews ] = useState ( [
62
16
{
63
17
image : "https://avatars.githubusercontent.com/u/88154142?v=4" ,
@@ -289,25 +243,48 @@ export const ChannelStateProvider = ({ children }) => {
289
243
video . setAttribute ( "muted" , "true" ) ;
290
244
} ;
291
245
292
- const changeChanneImage = async ( setNewChannelImage , e ) => {
293
- try {
294
- const avatarFile = e . target . files [ 0 ]
295
- const location = GetUid ( ) ;
296
- const { data, error } = await supabase
297
- . storage
298
- . from ( 'channel-images' )
299
- . upload ( location , avatarFile , {
300
- cacheControl : '3600' ,
301
- upsert : true
302
- } )
303
- const { path} = data ;
304
- const channelImage = `https://lumsrpmlumtfpbbafpug.supabase.co/storage/v1/object/public/channel-images/${ path } ` ;
305
- setNewChannelImage ( channelImage ) ;
306
- setCurrentChanne ( { ...currentChannel , channelImage : channelImage } )
307
- await supabase . from ( 'channels' ) . update ( { channelImage : channelImage } ) . eq ( 'uid' , currentChannel ?. uid )
308
- e . target . value = '' ;
309
- } catch { err => console . log ( err ) }
310
- }
246
+ const changeChannelImage = async ( e , setNewChannelImage ) => {
247
+ const avatarImage = e . target . files [ 0 ] ;
248
+ const location = uid ( ) ;
249
+ const { data, error } = await supabase . storage
250
+ . from ( "channel-images" )
251
+ . upload ( location , avatarImage , {
252
+ cacheControl : "3600" ,
253
+ upsert : false ,
254
+ } ) ;
255
+ const path = data ?. path ;
256
+ const channelImage = `https://lumsrpmlumtfpbbafpug.supabase.co/storage/v1/object/public/channel-images/${ path } ` ;
257
+ setNewChannelImage ( channelImage ) ;
258
+ await supabase
259
+ . from ( "channels" )
260
+ . update ( { channelImage : channelImage } )
261
+ . eq ( 'uid' , currentChannel ?. uid )
262
+ setCurrentChannel ( { ...currentChannel , channelImage : channelImage } ) ;
263
+ e . target . value = "" ;
264
+ } ;
265
+
266
+
267
+
268
+ const changeChannelBannerImage = async ( e , setNewBannerImage ) => {
269
+ console . log ( 'uploading....' )
270
+ const avatarImage = e . target . files [ 0 ] ;
271
+ const location = uid ( ) ;
272
+ const { data, error } = await supabase . storage
273
+ . from ( "channel-banner-images" )
274
+ . upload ( location , avatarImage , {
275
+ cacheControl : "3600" ,
276
+ upsert : false ,
277
+ } ) ;
278
+ const path = data ?. path ;
279
+ const bannerImage = `https://lumsrpmlumtfpbbafpug.supabase.co/storage/v1/object/public/channel-banner-images/${ path } ` ;
280
+ setNewBannerImage ( bannerImage ) ;
281
+ await supabase
282
+ . from ( "channels" )
283
+ . update ( { channelBannerImage : bannerImage } )
284
+ . eq ( 'uid' , currentChannel ?. uid )
285
+ setCurrentChannel ( { ...currentChannel , channelBannerImage : bannerImage } ) ;
286
+ e . target . value = "" ;
287
+ } ;
311
288
312
289
const channelSearches = [
313
290
"hello world" ,
@@ -613,7 +590,8 @@ export const ChannelStateProvider = ({ children }) => {
613
590
setThumbnailDialog,
614
591
handleLogin,
615
592
getVideoThumbnail,
616
- changeChanneImage
593
+ changeChannelImage,
594
+ changeChannelBannerImage
617
595
} }
618
596
>
619
597
{ children }
0 commit comments