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

Enhancement/event timeframes #81

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 36 additions & 2 deletions apps/kvarteret/components/HappeningToday.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { Title } from "dak-components";
import TranslatedField, {
useTranslation,
} from "dak-components/lib/components/TranslatedField";
import { Event } from "dak-components/lib/cms/queries/events";

const HappeningToday = ({ events }: { events: Event[] }) => {
const HappeningToday = ({ events }: { events: { time: String; room: String; title: String; }[] }) => {
return (

/* Creates the element wrapper */
<div className="happening-today">
<Title underlined>
<TranslatedField tKey="index-happening-today" />
</Title>

{/* Creates the event elements */}
<div className="happening-today-content">
<TodayItem
bold
Expand All @@ -20,16 +23,47 @@ const HappeningToday = ({ events }: { events: Event[] }) => {
title: useTranslation("event"),
}}
/>

{/* Maps a unique key to the event properties */}
{events.map((x, i) => (
<TodayItem key={i} event={x} />
))}
</div>

{/* Creates different elements if there is no events */}
{events.length <= 0 && (
<div className="nothing-happening">
<TranslatedField tKey="index-nothing-happening-today" />
</div>
)}

{/* CSS for the elements above */}
<style jsx>
{`

.happening-today-content {
gap: 10px;
display: grid;
margin-top: 5px;
grid-template-columns: fit-content(200px) fit-content(200px) 1fr;
}

@media (max-width: 768px) {
.happening-today-content {
gap: 0;
display: grid;
grid-template-rows: repeat(auto-fit, 1fr);
}
}

.nothing-happening {
margin-top: 10px;
}

`}
</style>
</div>

);
};

Expand Down
6 changes: 5 additions & 1 deletion apps/kvarteret/components/TodayItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const TodayItem = ({ event, bold = false }) => {
import { Event } from "dak-components/lib/cms/queries/events";
import { CrescatEvent } from "dak-components/lib/crescat";

const TodayItem = ({ event, bold = false }: { event: { time: String; room: String; title: String; }; bold?: boolean }) => {
Cengelsen marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
<div className="time">{event.time}</div>
Expand All @@ -18,6 +21,7 @@ const TodayItem = ({ event, bold = false }) => {
.title {
margin-bottom: 10px;
}

}
`}
</style>
Expand Down
29 changes: 0 additions & 29 deletions packages/dak-components/lib/crescat.js

This file was deleted.

57 changes: 57 additions & 0 deletions packages/dak-components/lib/crescat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import axios, { AxiosRequestHeaders } from 'axios'

import cache from 'memory-cache';

// Fetches the data from a given URL
const cachedGet = async (url: string, headers: AxiosRequestHeaders) => {
const cachedResponse = cache.get(url);
if (cachedResponse) {
return cachedResponse;
}

const cacheTime = 1000 * 60 * 30; //Cached for 1 minutes
const response = await axios.get(url, {
headers
});

// Establishes the data from the URL-response
const data = response.data;
cache.put(url, data, cacheTime);
return data;
}

const getEvents = async () => {
const crescatData = await cachedGet("https://app.crescat.io/external/v1/calendar", {
Authorization: `Bearer ${process.env.CRESCAT_TOKEN}`
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
}) as CrescatEvent[];

=> Then you will get great typing help


return crescatData.filter(x => x.fields.some(x => x.id === 70879));
}

export { getEvents };

// Type definition for the crescatData
export interface CrescatEvent {
id: number;
name: string;
start: Date;
end: Date;
event_type_id: number;
rooms: Room[];
show_times: any[];
fields: Field[];
}

export interface Field {
value: null | string;
show_time_id: null;
id: number;
}

export interface Room {
name: string;
id: number;
title: null | string;
start: Date;
end: Date;
}