Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added goat-counter analytics #635

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions pages/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,23 @@ const getEventClassByEvent = (event) => {

function Events({ events }) {
const [activeEvent, setActiveEvent] = useState(null);
const [indexedEvents, setIndexedEvents] = useState(events.map((event, index) => ({...event, id: index})));

const [indexedEvents, setIndexedEvents] = useState(() => {
// Check if events exist and have the expected structure
if (!Array.isArray(events)) return [];
return events.map((event, index) => ({...event, id: index}));
});

// Handle changes from Filters
const handleFilteredEvents = (newEvents) => {
// Validate newEvents before updating
if (Array.isArray(newEvents)) {
setIndexedEvents(newEvents);
} else {
// Optional: Handle unexpected newEvents format (maybe set to an empty array or log an error)
setIndexedEvents([]);
}
};

return (
<Layout>
Expand All @@ -58,7 +74,8 @@ function Events({ events }) {
</p>
<div className={styles['calendar-view-container']}>
<div>
<Filters handleChange={(newEvents) => setIndexedEvents(newEvents)}/>
<Filters handleChange={handleFilteredEvents} />
{indexedEvents.length ? ( // Check if we have events to show
<Calendar
localizer={localizer}
events={indexedEvents}
Expand All @@ -78,6 +95,9 @@ function Events({ events }) {
agenda: true,
}}
/>
) : (
<p>No events available at the moment. Please check back later.</p>
)}
</div>
<SelectedEvent event={activeEvent}/>
</div>
Expand All @@ -94,19 +114,25 @@ function Events({ events }) {
}

export const getStaticProps = async () => {
const events = await getAllEvents();
// Attempt to replace new lines with <br/>, doesnt work
// const processedEvents = events.map((event) => (
// {...event, description: <>{event.description.replace(/\n/g, '<br/>')}</>}));
// console.log(processedEvents);

return {
props: {
events: events,
},

revalidate: 3600,
};
try {
const events = await getAllEvents();
return {
props: {
events: events,
},
revalidate: 3600,
};
} catch (error) {
// eslint-disable-next-line no-console
console.error('Failed to fetch events:', error.message);
return {
props: {
events: [], // Return empty array as fallback
},
revalidate: 3600,
};
}
};

export default Events;

8 changes: 8 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextSeo } from 'next-seo';
import Link from 'next/link';
import React from 'react';
import Head from 'next/head';

Check warning on line 4 in pages/index.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

`next/head` import should occur before import of `next/link`

import Banner from '../components/Banner';
import Carousel from '../components/Carousel';
Expand All @@ -11,10 +12,17 @@
import SocialMedia from '../components/SocialMedia';
import data from '../data';


function Home () {
const { carousel, committees, news } = data;
return (
<Layout>
<Head>
<script
data-goatcounter="https://uclaacm.goatcounter.com/count"
async src="//gc.zgo.at/count.js">
</script>
</Head>
<NextSeo
title="Home | ACM at UCLA"
description="The ACM Student Chapter at UCLA is UCLA's largest tech community, focused on making tech as accessible as possible. We're split up into an array of committees and initiatives that each focus on a specific area of computer science. Everyone is welcome to join - regardless of major, prior experience, or anything else!"
Expand Down
Loading