1
- import { useState , useEffect } from 'react'
2
- import { supabase } from '../lib/api'
3
1
import Auth from '../components/Auth'
4
2
import Account from '../components/Account'
5
- import ProfileCard from '../components/ProfileCard'
6
- import { AuthSession , Subscription , SupabaseRealtimePayload } from '../../../dist/main'
7
- import { Profile } from '../lib/constants'
8
-
9
- var realtimeProfiles : Subscription | null
3
+ import ProfileList from '../components/ProfileList'
4
+ import { useState , useEffect } from 'react'
5
+ import { supabase } from '../lib/api'
6
+ import { AuthSession } from '@supabase/supabase-js'
10
7
11
8
export default function Home ( ) {
12
9
const [ session , setSession ] = useState < AuthSession | null > ( null )
13
- const [ profiles , setProfiles ] = useState < Profile [ ] > ( [ ] )
14
10
15
11
useEffect ( ( ) => {
16
12
setSession ( supabase . auth . session ( ) )
17
- getPublicProfiles ( )
18
13
19
14
supabase . auth . onAuthStateChange ( ( _event : string , session : AuthSession | null ) => {
20
15
setSession ( session )
21
16
} )
22
-
23
- realtimeProfiles = supabase
24
- . from ( 'profiles' )
25
- . on ( '*' , ( payload : SupabaseRealtimePayload < Profile > ) => {
26
- setProfiles ( [ payload . new , ...profiles ?. filter ( ( x ) => x . id != payload . new . id ) ] )
27
- } )
28
- . subscribe ( )
29
-
30
- return ( ) => {
31
- supabase . removeSubscription ( realtimeProfiles )
32
- realtimeProfiles = null
33
- }
34
17
} , [ ] )
35
18
36
- async function getPublicProfiles ( ) {
37
- try {
38
- const { data, error } = await supabase
39
- . from ( 'profiles' )
40
- . select ( 'id, username, avatar_url, website, updated_at' )
41
- . order ( 'updated_at' , { ascending : false } )
42
- if ( error ) {
43
- throw error
44
- }
45
- console . log ( 'data' , data )
46
- setProfiles ( data )
47
- } catch ( error ) {
48
- console . log ( 'error' , error . message )
49
- }
50
- }
51
-
52
19
return (
53
20
< div
54
21
style = { {
@@ -62,16 +29,12 @@ export default function Home() {
62
29
{ ! session ? (
63
30
< Auth />
64
31
) : (
65
- < div style = { { display : 'flex' , gap : 20 , width : '50%' } } >
66
- < div className = "flex flex-1 " >
32
+ < div className = "flex w-half" style = { { gap : 10 } } >
33
+ < div className = "flex column w-half " >
67
34
< Account key = { session . user . id } session = { session } />
68
35
</ div >
69
- < div className = "flex flex-1" >
70
- { profiles ?. map ( ( profile ) => (
71
- < div key = { profile . id } >
72
- < ProfileCard profile = { profile } />
73
- </ div >
74
- ) ) }
36
+ < div className = "flex column w-half" style = { { gap : 20 } } >
37
+ < ProfileList />
75
38
</ div >
76
39
</ div >
77
40
) }
0 commit comments