Fetch event data based on match param

This commit is contained in:
Aarni Halinen
2020-02-22 17:38:14 +02:00
parent c27607b9e7
commit 920c6275ce
2 changed files with 42 additions and 3 deletions
+6
View File
@@ -7,8 +7,14 @@ const url = `${process.env.API_URL}/events/`;
export interface Event {
id: number;
title: string;
title_fi: string;
title_en: string;
description: string;
description_fi: string;
description_en: string;
content: string;
content_fi: string;
content_en: string;
start_time: string;
end_time: string;
tags: Tag[];
+36 -3
View File
@@ -1,18 +1,51 @@
import * as React from "react";
import Helmet from "react-helmet";
import "./EventPage.scss";
import { Event, getEvent } from "../../models/Event";
import { RouteComponentProps } from "react-router-dom";
interface MatchParams {
id: string;
}
export interface EventPageProps {}
export interface EventPageState {}
export interface EventPageOwnProps {}
export interface EventPageState {
event?: Event;
}
type EventPageProps = EventPageOwnProps & RouteComponentProps<MatchParams>
class EventPage extends React.Component<EventPageProps, EventPageState> {
constructor(props: EventPageProps) {
super(props);
const { id } = this.props.match.params;
this.state = {
event: null
}
this.fetchEvent(Number(id));
}
fetchEvent(id: number) {
const eventPromise = getEvent(id);
eventPromise.then(event => {
this.setState({
event,
});
});
return eventPromise;
}
render() {
const { event } = this.state;
if (!event) return <div>Loading</div>
return (
<div className="event-page">
<Helmet>
<link rel="canonical" href="https://sik.ayy.fi/INSERT_PATH_HERE!" />
</Helmet>
Event Page
{event.title_fi}
</div>
);
}