Skip to content

Commit 64685f6

Browse files
Prettify storage example app
1 parent 98d85cf commit 64685f6

File tree

8 files changed

+269
-47
lines changed

8 files changed

+269
-47
lines changed

example/next-storage/components/Account.tsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import Avatar from './Avatar'
55
import { AuthSession } from '../../../dist/main'
66
import { DEFAULT_AVATARS_BUCKET, Profile } from '../lib/constants'
77

8-
export default function Account({ session }: { session: AuthSession }) {
8+
export default function Account({
9+
session,
10+
onSaveComplete,
11+
}: {
12+
session: AuthSession
13+
onSaveComplete: Function
14+
}) {
915
const [loading, setLoading] = useState<boolean>(true)
1016
const [uploading, setUploading] = useState<boolean>(false)
1117
const [avatar, setAvatar] = useState<string | null>(null)
@@ -111,33 +117,18 @@ export default function Account({ session }: { session: AuthSession }) {
111117
alert(error.message)
112118
} finally {
113119
setLoading(false)
120+
onSaveComplete()
114121
}
115122
}
116123

117124
return (
118-
<div
119-
style={{
120-
minWidth: 250,
121-
maxWidth: 600,
122-
margin: 'auto',
123-
display: 'flex',
124-
flexDirection: 'column',
125-
gap: 20,
126-
}}
127-
>
128-
<div className="card">
129-
<div>
130-
<Avatar url={avatar} size={270} />
131-
</div>
132-
<UploadButton onUpload={uploadAvatar} loading={uploading} />
133-
</div>
134-
125+
<div className="account">
135126
<div>
136127
<label htmlFor="email">Email</label>
137128
<input id="email" type="text" value={session.user.email} disabled />
138129
</div>
139130
<div>
140-
<label htmlFor="username">Username</label>
131+
<label htmlFor="username">Name</label>
141132
<input
142133
id="username"
143134
type="text"
@@ -154,10 +145,23 @@ export default function Account({ session }: { session: AuthSession }) {
154145
onChange={(e) => setWebsite(e.target.value)}
155146
/>
156147
</div>
148+
<div>
149+
<label htmlFor="avatar">Avatar image</label>
150+
<div className="avatarField">
151+
<div className="avatarContainer">
152+
{avatar ? (
153+
<Avatar url={avatar} size={40} />
154+
) : (
155+
<div className="avatarPlaceholder">?</div>
156+
)}
157+
</div>
158+
<UploadButton onUpload={uploadAvatar} loading={uploading} />
159+
</div>
160+
</div>
157161

158162
<div>
159163
<button className="button block primary" onClick={() => updateProfile()} disabled={loading}>
160-
{loading ? 'Loading ...' : 'Update'}
164+
{loading ? 'Loading ...' : 'Save and preview'}
161165
</button>
162166
</div>
163167

example/next-storage/components/Auth.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ export default function Auth({}) {
1010
try {
1111
setLoading(true)
1212
const { error, user } = await supabase.auth.signIn({ email })
13-
14-
if (error) {
15-
throw error
16-
}
17-
13+
if (error) throw error
1814
console.log('user', user)
1915
alert('Check your email for the login link!')
2016
} catch (error) {
@@ -26,18 +22,23 @@ export default function Auth({}) {
2622
}
2723

2824
return (
29-
<div style={{ display: 'flex', gap: 20, flexDirection: 'column' }}>
30-
<div>
31-
<label>Email</label>
25+
<div className="authContainer">
26+
<div className="authTitle">
27+
<h1 className="header">Experience our open-source storage system</h1>
28+
<p className="description">
29+
Through a simple profile management example. Create your user profile and upload an avatar
30+
image - Fast, simple, secure.
31+
</p>
32+
</div>
33+
<div className="authWidget" style={{ display: 'flex', gap: 20, flexDirection: 'column' }}>
34+
<p className="description">Sign in via magic link with your email below</p>
3235
<input
36+
className="inputField"
3337
type="email"
3438
placeholder="Your email"
3539
value={email}
3640
onChange={(e) => setEmail(e.target.value)}
3741
/>
38-
</div>
39-
40-
<div>
4142
<button
4243
onClick={(e) => {
4344
e.preventDefault()
@@ -46,9 +47,13 @@ export default function Auth({}) {
4647
className={'button block'}
4748
disabled={loading}
4849
>
49-
{loading ? 'Loading ..' : 'Send magic link'}
50+
{loading ? <img className="loader" src="loader.svg" /> : <span>Send magic link</span>}
5051
</button>
5152
</div>
53+
<div className="footer">
54+
Powered by
55+
<img src="logo.png" />
56+
</div>
5257
</div>
5358
)
5459
}

example/next-storage/components/ProfileCard.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@ import Avatar from './Avatar'
44
export default function ProfileCard({ profile }: { profile: Profile }) {
55
const lastUpdated = profile.updated_at ? new Date(profile.updated_at) : null
66
return (
7-
<div className="card">
8-
<Avatar url={profile.avatar_url} size={50} />
9-
<p>Username: {profile.username}</p>
10-
<p>Website: {profile.website}</p>
11-
<p>
7+
<>
8+
<div className="profileCard">
9+
<div className="avatarContainer">
10+
<Avatar url={profile.avatar_url} size={200} />
11+
</div>
12+
<div className="userInfo">
13+
<p className="username">{profile.username}</p>
14+
<a href={profile.website} target="_blank" className="website">
15+
{profile.website}
16+
</a>
17+
</div>
18+
</div>
19+
<p style={{ marginTop: '0px' }}>
1220
<small>
1321
Last updated{' '}
1422
{lastUpdated
1523
? `${lastUpdated.toLocaleDateString()} ${lastUpdated.toLocaleTimeString()}`
1624
: 'Never'}
1725
</small>
1826
</p>
19-
</div>
27+
</>
2028
)
2129
}

example/next-storage/components/ProfileList.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export default function ProfileList() {
1010
const [profiles, setProfiles] = useState<Profile[]>([])
1111

1212
useEffect(() => {
13-
getPublicProfiles()
13+
// getPublicProfiles()
14+
getUserProfile()
1415

1516
realtimeProfiles = supabase
1617
.from('profiles')
@@ -27,6 +28,23 @@ export default function ProfileList() {
2728
setProfiles([updated, ...otherProfiles])
2829
}
2930

31+
async function getUserProfile() {
32+
const user = supabase.auth.user()
33+
try {
34+
const { data, error } = await supabase
35+
.from('profiles')
36+
.select('id, username, avatar_url, website, updated_at')
37+
.eq('id', user.id)
38+
.order('updated_at', { ascending: false })
39+
if (error) {
40+
throw error
41+
}
42+
setProfiles(data)
43+
} catch (error) {
44+
console.log('error', error.message)
45+
}
46+
}
47+
3048
async function getPublicProfiles() {
3149
try {
3250
const { data, error } = await supabase
@@ -36,7 +54,6 @@ export default function ProfileList() {
3654
if (error) {
3755
throw error
3856
}
39-
console.log('data', data)
4057
setProfiles(data)
4158
} catch (error) {
4259
console.log('error', error.message)

example/next-storage/pages/index.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export default function Home() {
1616
})
1717
}, [])
1818

19+
const onSaveComplete = () => {
20+
console.log('complete')
21+
}
22+
1923
return (
2024
<div
2125
style={{
@@ -29,12 +33,20 @@ export default function Home() {
2933
{!session ? (
3034
<Auth />
3135
) : (
32-
<div className="flex w-half" style={{ gap: 10 }}>
33-
<div className="flex column w-half">
34-
<Account key={session.user.id} session={session} />
35-
</div>
36-
<div className="flex column w-half" style={{ gap: 20 }}>
37-
<ProfileList />
36+
<div style={{ width: '50%' }}>
37+
<p className="mainHeader">
38+
Let's set up a simple profile
39+
<span style={{ display: 'block', opacity: '50%', marginTop: '5px' }}>
40+
And watch it update on the right
41+
</span>
42+
</p>
43+
<div className="flex" style={{ gap: 10, width: '100%', justifyContent: 'space-between' }}>
44+
<div className="flex column" style={{ width: '45%' }}>
45+
<Account key={session.user.id} session={session} onSaveComplete={onSaveComplete} />
46+
</div>
47+
<div className="flex column" style={{ gap: 20, width: '45%' }}>
48+
<ProfileList />
49+
</div>
3850
</div>
3951
</div>
4052
)}
Lines changed: 1 addition & 0 deletions
Loading
10.3 KB
Loading

0 commit comments

Comments
 (0)