Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from toplap/feat/title-description
Browse files Browse the repository at this point in the history
Add Stream `description` field
  • Loading branch information
munshkr authored Feb 9, 2024
2 parents 2011f8f + 6c83501 commit e14ba30
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 209 deletions.
34 changes: 28 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 20 additions & 14 deletions src/app/components/PerformanceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,41 @@ const PerformanceCard = ({
eventUrl,
}: Props): ReactElement => {
const [inCreateMode, setInCreateMode] = useState<boolean>(false);
const [currMuxyStream, setCurrMuxyStream] = useState<MuxyStream | EmptyMuxyStream>(muxyStream);
const [currMuxyStream, setCurrMuxyStream] = useState<
MuxyStream | EmptyMuxyStream
>(muxyStream);
const [inRemoveMode, setInRemoveMode] = useState<boolean>(false);
const [inEditMode, setInEditMode] = useState<boolean>(false);
const [removed, setRemoved] = useState<boolean>(false);

const startsAtHs = DateTime.fromISO(muxyStream.starts_at).toFormat("HH:mm LLL dd");
const endsAtHs = DateTime.fromISO(muxyStream.ends_at).toFormat("HH:mm LLL dd");
const startsAtHs = DateTime.fromISO(muxyStream.starts_at).toFormat(
"HH:mm LLL dd"
);
const endsAtHs = DateTime.fromISO(muxyStream.ends_at).toFormat(
"HH:mm LLL dd"
);

let text = null;
if ("publisher_name" in currMuxyStream) {
const { publisher_name, location, description, timezone } = currMuxyStream;
text = [publisher_name, location, description, timezone].join(" / ");
const { publisher_name, location, title, timezone } = currMuxyStream;
text = [publisher_name, location, title, timezone].join(" / ");
}

const resetFormStates = () => {
setInCreateMode(false);
setInRemoveMode(false);
setInEditMode(false);
}
};

const handleEditClick = () => {
resetFormStates();
setInEditMode((prevState) => !prevState)
setInEditMode((prevState) => !prevState);
};

const handleRemoveClick = () => {
resetFormStates();
setInRemoveMode((prevState) => !prevState);
}
};
const handleRemove = () => setRemoved(true);

return (
Expand Down Expand Up @@ -83,12 +89,12 @@ const PerformanceCard = ({
Remove
</button>
{inEditMode && "url" in currMuxyStream && (
<PerformanceEditForm
streamUrl={currMuxyStream.url}
currMuxyStream={currMuxyStream}
onSetInEditMode={setInEditMode}
setCurrMuxyStream={setCurrMuxyStream}
/>
<PerformanceEditForm
streamUrl={currMuxyStream.url}
currMuxyStream={currMuxyStream}
onSetInEditMode={setInEditMode}
setCurrMuxyStream={setCurrMuxyStream}
/>
)}
{inRemoveMode && "url" in currMuxyStream && (
<PerformanceDestroyForm
Expand Down
172 changes: 109 additions & 63 deletions src/app/components/PerformanceCreateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,118 @@
import React, { ReactElement, useState } from 'react';
import React, { ReactElement, useState } from "react";

interface Props {
eventUrl: string,
startsAt: string,
endsAt: string
eventUrl: string;
startsAt: string;
endsAt: string;
}

function PerformanceCreateForm({eventUrl, startsAt, endsAt}: Props): ReactElement {
const [name, setName] = useState<string>("");
const [email, setEmail] = useState<string>("");
const [description, setDescription] = useState<string>("");
const [streamkey, setStreamKey] = useState<string>("");
const [location, setLocation] = useState<string>("");
const muxyApiKey: string = (process.env.REACT_APP_MUXY_API_KEY as string);
const muxyUrl: string = (process.env.REACT_APP_MUXY_URL as string);
function PerformanceCreateForm({
eventUrl,
startsAt,
endsAt,
}: Props): ReactElement {
const [name, setName] = useState<string>("");
const [email, setEmail] = useState<string>("");
const [title, setTitle] = useState<string>("");
const [description, setDescription] = useState<string>("");
const [streamkey, setStreamKey] = useState<string>("");
const [location, setLocation] = useState<string>("");
const muxyApiKey: string = process.env.REACT_APP_MUXY_API_KEY as string;
const muxyUrl: string = process.env.REACT_APP_MUXY_URL as string;

const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
fetch(`${muxyUrl}/streams/`, {
method: "post",
headers: new Headers({
Authorization: `Api-Key ${muxyApiKey}`,
"Content-Type": "application/json",
Accept: "application/json",
}),
body: JSON.stringify({
publisher_name: name,
publisher_email: email,
description: description,
location: location,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
event: eventUrl, // This needs to come from the muxy event (isn't available right now)
starts_at: startsAt, // This needs to be calculated before
ends_at: endsAt, // This needs to be calculated before
}),
})
.then((res) => res.json())
.then((data) => {
setStreamKey(data.key);
})
.catch(console.error);
}
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
fetch(`${muxyUrl}/streams/`, {
method: "post",
headers: new Headers({
Authorization: `Api-Key ${muxyApiKey}`,
"Content-Type": "application/json",
Accept: "application/json",
}),
body: JSON.stringify({
publisher_name: name,
publisher_email: email,
title: title,
description: description,
location: location,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
event: eventUrl, // This needs to come from the muxy event (isn't available right now)
starts_at: startsAt, // This needs to be calculated before
ends_at: endsAt, // This needs to be calculated before
}),
})
.then((res) => res.json())
.then((data) => {
setStreamKey(data.key);
})
.catch(console.error);
};

return (
<>
{streamkey && (
<div>
<p>You have successfully registered for the event. Your streamkey is <b>{streamkey}</b> </p>
<p>You should have received this as an email too. </p>
<p>Save this key well, you will need it for the event and also to delete your slot again. </p>
<p>When this page is reloaded, the key will no longer be displayed. </p>
</div>
)}
{!streamkey && (
<form className="PerformanceCreateForm" onSubmit={handleSubmit}>
<input id="name" type="text" placeholder="Name" value={name}
onChange={e => setName(e.target.value)} required />
<input id="email" type="text" placeholder="E-Mail" value={email}
onChange={e => setEmail(e.target.value)} required />
<input id="description" type="text" placeholder="Description" value={description}
onChange={e => setDescription(e.target.value)} required />
<input id="location" type="text" placeholder="Location" value={location}
onChange={e => setLocation(e.target.value)} required />
<input type="submit" className="card-button" value="Rave On"/>
</form>
)}
</>
);
return (
<>
{streamkey && (
<div>
<p>
You have successfully registered for the event. Your streamkey is{" "}
<b>{streamkey}</b>{" "}
</p>
<p>You should have received this as an email too. </p>
<p>
Save this key well, you will need it for the event and also to
delete your slot again.{" "}
</p>
<p>
When this page is reloaded, the key will no longer be displayed.{" "}
</p>
</div>
)}
{!streamkey && (
<form className="PerformanceCreateForm" onSubmit={handleSubmit}>
<input
id="name"
type="text"
placeholder="Name"
value={name}
onChange={(e) => setName(e.target.value)}
required
/>
<input
id="email"
type="text"
placeholder="E-Mail"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
<input
id="title"
type="text"
placeholder="Title"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
<textarea
id="description"
placeholder="Description (used for archive videos)"
value={description}
onChange={(e) => setDescription(e.target.value)}
rows={3}
maxLength={1000}
/>
<input
id="location"
type="text"
placeholder="Location"
value={location}
onChange={(e) => setLocation(e.target.value)}
required
/>
<input type="submit" className="card-button" value="Rave On" />
</form>
)}
</>
);
}

export default PerformanceCreateForm;
Loading

0 comments on commit e14ba30

Please sign in to comment.