1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-21 22:24:22 +00:00

Start building dates framework

This commit is contained in:
Steffo 2022-06-06 03:15:44 +02:00
parent f942a8e556
commit deebefbc89
Signed by: steffo
GPG key ID: 6965406171929D01
10 changed files with 114 additions and 9 deletions

View file

@ -0,0 +1,28 @@
import { ReactNode } from "react"
type FormDateRangeProps = {
icon: ReactNode,
start: ReactNode,
connector: ReactNode,
end: ReactNode,
}
export function FormDateRange(props: FormDateRangeProps) {
return (
<div className="form-daterange">
<div className="form-daterange-icon">
{props.icon}
</div>
<div className="form-daterange-start">
{props.start}
</div>
<div className="form-daterange-connector">
{props.connector}
</div>
<div className="form-daterange-end">
{props.end}
</div>
</div>
)
}

View file

@ -0,0 +1,25 @@
import { faClock } from "@fortawesome/free-solid-svg-icons"
import { FestaIcon } from "../extensions/FestaIcon"
import { FormDateRange } from "../FormDateRange"
export function EditableDateRange() {
// TODO
return (
<FormDateRange
icon={
<FestaIcon icon={faClock}/>
}
start={<>
</>}
connector={<>
&nbsp;&nbsp;
</>}
end={<>
</>}
/>
)
}

View file

@ -1,9 +1,11 @@
import { ReactNode } from "react"
import { FormDateRange } from "../FormDateRange"
type ViewEventProps = {
title: ReactNode
postcard: ReactNode
description: ReactNode
title: ReactNode,
postcard: ReactNode,
description: ReactNode,
datetime: ReactNode,
}
@ -19,6 +21,9 @@ export function ViewEvent(props: ViewEventProps) {
<div className="view-event-description">
{props.description}
</div>
<FormDateRange
className="view-event-daterange"
/>
</main>
)
}

View file

@ -23,6 +23,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const update = {
name: req.body.name,
postcard: req.body.postcard ?? null,
description: req.body.description,
startingAt: req.body.startingAt,
endingAt: req.body.endingAt,
}
await restInPeace(req, res, {

View file

@ -21,6 +21,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
creatorId: user.id,
name: req.body.name,
postcard: req.body.postcard ?? null,
description: req.body.description,
startingAt: req.body.startingAt,
endingAt: req.body.endingAt,
}
await restInPeace(req, res, {

View file

@ -14,6 +14,8 @@ import { Postcard } from "../../components/postcard/Postcard";
import { ViewContent } from "../../components/view/ViewContent";
import { EditablePostcard } from "../../components/editable/EditablePostcard";
import { ViewEvent } from "../../components/view/ViewEvent";
import { EditableDateTime } from "../../components/editable/EditableDateTime";
import { FormDateRange } from "../../components/FormDateRange";
export async function getServerSideProps(context: NextPageContext) {
@ -50,6 +52,8 @@ export default function PageEventDetail({event}: PageEventDetailProps) {
const [title, setTitle] = useState<string>(event.name)
const [description, setDescription] = useState<string>(event.description)
const [postcard, setPostcard] = useState<string | null>(event.postcard)
const [startingAt, setStartingAt] = useState<string | null>(event.startingAt?.toISOString() ?? null)
const [endingAt, setEndingAt] = useState<string | null>(event.endingAt?.toISOString() ?? null)
const setPostcardBlob = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
@ -97,6 +101,18 @@ export default function PageEventDetail({event}: PageEventDetailProps) {
placeholder={t("eventDetailsDescriptionPlaceholder")}
/>
}
datetime={
<FormDateRange
startProps={{
value: startingAt ?? undefined,
onChange: (e: ChangeEvent<HTMLInputElement>) => setStartingAt(e.target.value),
}}
endProps={{
value: endingAt ?? undefined,
onChange: (e: ChangeEvent<HTMLInputElement>) => setEndingAt(e.target.value),
}}
/>
}
/>
</EditingContext.Provider>
</>

View file

@ -76,15 +76,19 @@ model Token {
/// The core of the project, a single instance of people gathering in a certain place at a certain time.
model Event {
/// An unique url-safe string identifying the event, and allowing it to be accessed at `/events/SLUG`.
slug String @id
slug String @id
/// The id of the {@link User} who created the event.
creatorId String @db.Uuid
creatorId String @db.Uuid
/// The {@link User} who created the event.
creator User @relation(fields: [creatorId], references: [id])
creator User @relation(fields: [creatorId], references: [id])
/// The name of the event.
name String
/// The URL to the postcard of the event.
postcard String?
/// The description of the event. It will be parsed in Markdown!
description String @default("")
description String @default("")
/// The time when the event will start at.
startingAt DateTime?
/// The time when the even will end at.
endingAt DateTime?
}

View file

@ -0,0 +1,15 @@
.form-daterange {
display: flex;
flex-direction: row;
align-items: center;
gap: 4px;
}
.form-daterange-start, .form-daterange-end {
flex-grow: 1;
}
.form-daterange-icon, .form-daterange-connector {
flex-grow: 0;
}

View file

@ -4,9 +4,10 @@
"x1 ti ti ti x4"
"x1 x2 po x3 x4"
"x1 x2 de x3 x4"
"x1 x2 dr x3 x4"
;
grid-template-columns: 3fr 1fr 800px 1fr 3fr;
grid-template-rows: auto auto 1fr;
grid-template-rows: auto auto 1fr auto;
row-gap: 4px;
@ -25,3 +26,7 @@
.view-event-description {
grid-area: de;
}
.view-event-daterange {
grid-area: dr;
}

View file

@ -15,6 +15,7 @@
@import "components/toolbar.css";
@import "components/form-monorow.css";
@import "components/error.css";
@import "components/form-daterange.css";
* {
@ -27,7 +28,7 @@
text-shadow: none;
}
*[disabled] {
*[disabled], .disabled {
opacity: 0.2;
cursor: not-allowed;
}