Skip to content

Commit e5f189a

Browse files
committed
Removed the final CSS module
1 parent c8e301c commit e5f189a

File tree

7 files changed

+90
-79
lines changed

7 files changed

+90
-79
lines changed

example/next-storage/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,4 @@ begin;
3131
commit;
3232

3333
alter publication supabase_realtime add table profiles;
34-
35-
3634
```

example/next-storage/components/Account.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DEFAULT_AVATARS_BUCKET, Profile } from '../lib/constants'
77

88
export default function Account({ session }: { session: AuthSession }) {
99
const [loading, setLoading] = useState<boolean>(true)
10+
const [uploading, setUploading] = useState<boolean>(false)
1011
const [avatar, setAvatar] = useState<string | null>(null)
1112
const [username, setUsername] = useState<string | null>(null)
1213
const [website, setWebsite] = useState<string | null>(null)
@@ -22,12 +23,13 @@ export default function Account({ session }: { session: AuthSession }) {
2223

2324
async function uploadAvatar(event: ChangeEvent<HTMLInputElement>) {
2425
try {
25-
const user = supabase.auth.user()
26+
setUploading(true)
2627

2728
if (!event.target.files || event.target.files.length == 0) {
2829
throw 'You must select an image to upload.'
2930
}
3031

32+
const user = supabase.auth.user()
3133
const file = event.target.files[0]
3234
const fileExt = file.name.split('.').pop()
3335
const fileName = `${session?.user.id}${Math.random()}.${fileExt}`
@@ -52,6 +54,8 @@ export default function Account({ session }: { session: AuthSession }) {
5254
setAvatar(filePath)
5355
} catch (error) {
5456
alert(error.message)
57+
} finally {
58+
setUploading(false)
5559
}
5660
}
5761

@@ -125,7 +129,7 @@ export default function Account({ session }: { session: AuthSession }) {
125129
<div>
126130
<Avatar url={avatar} size={270} />
127131
</div>
128-
<UploadButton onUpload={uploadAvatar} />
132+
<UploadButton onUpload={uploadAvatar} loading={uploading} />
129133
</div>
130134

131135
<div>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import ProfileCard from '../components/ProfileCard'
2+
import { Profile } from '../lib/constants'
3+
import { Subscription, SupabaseRealtimePayload } from '@supabase/supabase-js'
4+
import { supabase } from '../lib/api'
5+
import { useState, useEffect } from 'react'
6+
7+
var realtimeProfiles: Subscription | null
8+
9+
export default function ProfileList() {
10+
const [profiles, setProfiles] = useState<Profile[]>([])
11+
12+
useEffect(() => {
13+
getPublicProfiles()
14+
15+
realtimeProfiles = supabase
16+
.from('profiles')
17+
.on('*', (payload: SupabaseRealtimePayload<Profile>) => {
18+
console.log('profiles', profiles)
19+
const otherProfiles = profiles?.filter((x) => x.id != payload.new.id)
20+
console.log('otherProfiles', otherProfiles)
21+
setProfiles([payload.new, ...otherProfiles])
22+
})
23+
.subscribe()
24+
25+
return () => {
26+
supabase.removeSubscription(realtimeProfiles)
27+
realtimeProfiles = null
28+
}
29+
}, [])
30+
31+
async function getPublicProfiles() {
32+
try {
33+
const { data, error } = await supabase
34+
.from('profiles')
35+
.select('id, username, avatar_url, website, updated_at')
36+
.order('updated_at', { ascending: false })
37+
if (error) {
38+
throw error
39+
}
40+
console.log('data', data)
41+
setProfiles(data)
42+
} catch (error) {
43+
console.log('error', error.message)
44+
}
45+
}
46+
47+
return (
48+
<>
49+
{profiles?.map((profile) => (
50+
<ProfileCard profile={profile} key={profile.id} />
51+
))}
52+
</>
53+
)
54+
}

example/next-storage/components/UploadButton.module.css

Lines changed: 0 additions & 21 deletions
This file was deleted.

example/next-storage/components/UploadButton.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import { ChangeEventHandler } from 'react'
2-
import styles from './UploadButton.module.css'
32

43
export type UploadButtonProps = {
54
onUpload: ChangeEventHandler<HTMLInputElement>
5+
loading: boolean
66
}
77

88
export default function UploadButton(props: UploadButtonProps) {
99
return (
10-
<div className={styles.container}>
11-
<label className={styles.label} htmlFor="single">
12-
Upload avatar
10+
<div>
11+
<label className="button primary block" htmlFor="single">
12+
{props.loading ? 'Uploading ...' : 'Upload'}
1313
</label>
1414
<input
15-
className={styles.input}
15+
style={{
16+
visibility: 'hidden',
17+
position: 'absolute',
18+
}}
1619
type="file"
1720
id="single"
1821
accept="image/*"
1922
onChange={props.onUpload}
23+
disabled={props.loading}
2024
/>
2125
</div>
2226
)

example/next-storage/pages/index.tsx

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,21 @@
1-
import { useState, useEffect } from 'react'
2-
import { supabase } from '../lib/api'
31
import Auth from '../components/Auth'
42
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'
107

118
export default function Home() {
129
const [session, setSession] = useState<AuthSession | null>(null)
13-
const [profiles, setProfiles] = useState<Profile[]>([])
1410

1511
useEffect(() => {
1612
setSession(supabase.auth.session())
17-
getPublicProfiles()
1813

1914
supabase.auth.onAuthStateChange((_event: string, session: AuthSession | null) => {
2015
setSession(session)
2116
})
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-
}
3417
}, [])
3518

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-
5219
return (
5320
<div
5421
style={{
@@ -62,16 +29,12 @@ export default function Home() {
6229
{!session ? (
6330
<Auth />
6431
) : (
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">
6734
<Account key={session.user.id} session={session} />
6835
</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 />
7538
</div>
7639
</div>
7740
)}

example/next-storage/styles/globals.css

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ input[disabled] {
4949

5050
/* Utils */
5151

52+
.w-half {
53+
width: 50%;
54+
}
55+
5256
.block {
5357
display: block;
5458
width: 100%;
@@ -62,18 +66,20 @@ input[disabled] {
6266
display: flex;
6367
}
6468
.flex.column {
65-
flex: column;
69+
flex-direction: column;
6670
}
6771
.flex.row {
68-
flex: row;
72+
flex-direction: row;
6973
}
7074
.flex.flex-1 {
7175
flex: 1 1 0;
7276
}
7377

7478
/* Button */
7579

76-
button {
80+
button,
81+
.button {
82+
color: var(--custom-color);
7783
border: var(--custom-border);
7884
background-color: var(--custom-bg-color);
7985
display: inline-block;
@@ -86,14 +92,17 @@ button {
8692
text-transform: uppercase;
8793
}
8894

89-
button.primary {
95+
button.primary,
96+
.button.primary {
9097
background-color: var(--custom-color-brand);
98+
border: 1px solid var(--custom-color-brand);
9199
}
92100

93101
/* Widgets */
94102

95103
.card {
96104
width: 100%;
105+
display: block;
97106
border: var(--custom-border);
98107
border-radius: var(--custom-border-radius);
99108
padding: var(--custom-spacing);

0 commit comments

Comments
 (0)