Skip to content

Commit aeb6da5

Browse files
committed
change staticEvents from object to map
1 parent 12d5eb1 commit aeb6da5

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

backend/example/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ def get_events(request):
9999
similar_events = find_similar_events(
100100
embedding=search_embedding, threshold=0.275
101101
)
102-
if similar_events:
103-
similar_event_ids = [event["id"] for event in similar_events]
104-
filtered_queryset = filtered_queryset.filter(id__in=similar_event_ids)
102+
similar_event_ids = [event["id"] for event in similar_events]
103+
filtered_queryset = filtered_queryset.filter(id__in=similar_event_ids)
105104
else:
106105
filtered_queryset = Events.objects.none()
107106

backend/scraping/get_static_events.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def main():
7676
logging.info(f"Writing to {output_path}...")
7777
with output_path.open("w", encoding="utf-8") as f:
7878
f.write('import { Event } from "@/hooks/useEvents";\n\n')
79-
f.write("export const staticEventsData: Record<string, Event> = {\n")
79+
f.write("export const staticEventsData = new Map<string, Event>([\n")
8080
for i, event in enumerate(events):
8181
event_id = str(event["id"])
82-
f.write(f" {format_value(event_id)}: {{\n")
82+
f.write(f" [{format_value(event_id)}, {{\n")
8383
f.write(f" id: {format_value(event_id)},\n")
8484
f.write(f' club_handle: {format_value(event["club_handle"])},\n')
8585
f.write(f' url: {format_value(event["url"])},\n')
@@ -94,11 +94,11 @@ def main():
9494
f.write(f' image_url: {format_value(event["image_url"])},\n')
9595
f.write(f' club_type: {format_value(event["club_type"])},\n')
9696
f.write(f' added_at: {format_value(event["added_at"])},\n')
97-
f.write(" }")
97+
f.write(" }]")
9898
if i < len(events) - 1:
9999
f.write(",")
100100
f.write("\n")
101-
f.write("};\n")
101+
f.write("]);\n")
102102
logging.info("Successfully updated staticEvents.ts")
103103
except Exception:
104104
logging.exception("An error occurred")

frontend/src/hooks/useEvents.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ export function useEvents(view: "grid" | "calendar") {
8282

8383
if (hasActiveFilters && data?.event_ids) {
8484
rawEvents = data.event_ids
85-
.map(id => staticEventsData[id])
86-
.filter(Boolean);
85+
.map(id => staticEventsData.get(id))
86+
.filter(Boolean) as Event[];
8787
} else {
88-
rawEvents = Object.values(staticEventsData);
88+
rawEvents = Array.from(staticEventsData.values());
8989
}
9090

9191
if (view === "grid") {

0 commit comments

Comments
 (0)