Skip to content

Commit 4dd8039

Browse files
committed
Good to go
1 parent f5def44 commit 4dd8039

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

src/app/harbor/tavern/map.tsx

+9-18
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default function Map({ tavernEvents, tavernPeople, selectedTavern }) {
3939
url="https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"
4040
/>
4141
<TavernMarkers people={tavernPeople} events={tavernEvents} />
42-
<UserLocation />
4342
<MapUpdater selectedTavern={selectedTavern} />
4443
</MapContainer>
4544
<Card className="mt-8 p-3 flex flex-row justify-center items-center gap-5 flex-wrap">
@@ -83,22 +82,6 @@ export default function Map({ tavernEvents, tavernPeople, selectedTavern }) {
8382
)
8483
}
8584

86-
function UserLocation() {
87-
const map = useMap()
88-
89-
useEffect(() => {
90-
if (navigator.geolocation) {
91-
navigator.geolocation.getCurrentPosition((loc) => {
92-
if (map !== null) {
93-
map.setView([loc.coords.latitude, loc.coords.longitude], 11)
94-
}
95-
})
96-
}
97-
}, [map])
98-
99-
return null
100-
}
101-
10285
function MapUpdater({
10386
selectedTavern,
10487
}: {
@@ -107,13 +90,21 @@ function MapUpdater({
10790
const map = useMap()
10891

10992
useEffect(() => {
110-
if (selectedTavern && selectedTavern.geocode && map) {
93+
if (!map) return
94+
95+
if (selectedTavern && selectedTavern.geocode) {
11196
const geocodeData = JSON.parse(
11297
atob(selectedTavern.geocode.slice(2).trim()),
11398
)
11499
if (geocodeData.o.status === 'OK') {
115100
map.setView([geocodeData.o.lat, geocodeData.o.lng], 11)
116101
}
102+
} else if (navigator.geolocation) {
103+
navigator.geolocation.getCurrentPosition((loc) => {
104+
if (map !== null) {
105+
map.setView([loc.coords.latitude, loc.coords.longitude], 11)
106+
}
107+
})
117108
}
118109
}, [selectedTavern, map])
119110

src/app/harbor/tavern/tavern.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
setTavernRsvpStatus,
77
getTavernRsvpStatus,
88
submitMyTavernLocation,
9+
getMyTavernLocation,
910
} from '@/app/utils/tavern'
1011
import { Card } from '@/components/ui/card'
1112
import dynamic from 'next/dynamic'
@@ -104,7 +105,9 @@ const RsvpStatusSwitcher = ({ tavernEvents, onTavernSelect }) => {
104105
value={whichTavern}
105106
className="ml-2 text-gray-600 rounded-sm"
106107
>
107-
<option value="">Select</option>
108+
<option value="" disabled>
109+
Select
110+
</option>
108111
{tavernEvents.map((te, idx) => (
109112
<option key={idx} value={te.id}>
110113
{te.locality}
@@ -127,11 +130,14 @@ export default function Tavern() {
127130
)
128131

129132
useEffect(() => {
130-
Promise.all([getTavernPeople(), getTavernEvents()]).then(([tp, te]) => {
133+
Promise.all([
134+
getTavernPeople(),
135+
getTavernEvents(),
136+
getMyTavernLocation(),
137+
]).then(([tp, te, myTavernLocation]) => {
131138
setTavernPeople(tp)
132139
setTavernEvents(te)
133-
134-
console.log({ te })
140+
setSelectedTavern(myTavernLocation)
135141
})
136142
}, [])
137143

src/app/utils/tavern.ts

+31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import Airtable from 'airtable'
44
import { getSession } from './auth'
5+
import { TavernEventItem } from '../harbor/tavern/tavern-utils'
56

67
Airtable.configure({
78
apiKey: process.env.AIRTABLE_API_KEY,
@@ -61,3 +62,33 @@ export const submitMyTavernLocation = async (tavernId: string) => {
6162
taverns_attendee: tavernId ? [tavernId] : [],
6263
})
6364
}
65+
66+
export const getMyTavernLocation: Promise<TavernEventItem> = async () => {
67+
// check auth
68+
const session = await getSession()
69+
if (!session) {
70+
return
71+
}
72+
if (!session.personId) {
73+
return
74+
}
75+
76+
// update status
77+
const base = Airtable.base(process.env.BASE_ID)
78+
79+
const foundTavern = await base('taverns')
80+
.select({
81+
filterByFormula: `FIND('${session.personId}', {attendee_record_ids})`,
82+
})
83+
.firstPage()
84+
.then((r) => r[0])
85+
86+
return {
87+
id: foundTavern.id,
88+
city: foundTavern.get('city'),
89+
geocode: foundTavern.get('map_geocode'),
90+
locality: foundTavern.get('locality'),
91+
attendeeCount: foundTavern.get('attendees_count'),
92+
organizers: foundTavern.get('organizers'),
93+
}
94+
}

0 commit comments

Comments
 (0)