Skip to content

Commit 685b1ed

Browse files
committed
Adds updated times to the cards
1 parent 7f51734 commit 685b1ed

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

example/next-storage/components/ProfileCard.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@ import { Profile } from '../lib/constants'
22
import Avatar from './Avatar'
33

44
export default function ProfileCard({ profile }: { profile: Profile }) {
5+
const lastUpdated = profile.updated_at ? new Date(profile.updated_at) : null
56
return (
67
<div className="card">
78
<Avatar url={profile.avatar_url} size={50} />
89
<p>Username: {profile.username}</p>
910
<p>Website: {profile.website}</p>
11+
<p>
12+
<small>
13+
Last updated{' '}
14+
{lastUpdated
15+
? `${lastUpdated.toLocaleDateString()} ${lastUpdated.toLocaleTimeString()}`
16+
: 'Never'}
17+
</small>
18+
</p>
1019
</div>
1120
)
1221
}

example/next-storage/components/ProfileList.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,25 @@ import { Subscription, SupabaseRealtimePayload } from '@supabase/supabase-js'
44
import { supabase } from '../lib/api'
55
import { useState, useEffect } from 'react'
66

7-
var realtimeProfiles: Subscription | null
8-
97
export default function ProfileList() {
108
const [profiles, setProfiles] = useState<Profile[]>([])
119

1210
useEffect(() => {
1311
getPublicProfiles()
1412

15-
realtimeProfiles = supabase
13+
const realtimeProfiles = supabase
1614
.from('profiles')
1715
.on('*', (payload: SupabaseRealtimePayload<Profile>) => profileUpdated(payload.new))
1816
.subscribe()
1917

2018
return () => {
2119
supabase.removeSubscription(realtimeProfiles)
22-
realtimeProfiles = null
2320
}
2421
}, [])
2522

2623
function profileUpdated(profile: Profile) {
2724
const otherProfiles = profiles?.filter((x) => x.id != profile.id)
25+
console.log('otherProfiles', otherProfiles)
2826
setProfiles([profile, ...otherProfiles])
2927
}
3028

example/next-storage/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export type Profile = {
88
avatar_url: string
99
username: string
1010
website: string
11+
updated_at: string
1112
}

0 commit comments

Comments
 (0)