1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-22 14:44:21 +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 { ReactNode } from "react"
import { FormDateRange } from "../FormDateRange"
type ViewEventProps = { type ViewEventProps = {
title: ReactNode title: ReactNode,
postcard: ReactNode postcard: ReactNode,
description: ReactNode description: ReactNode,
datetime: ReactNode,
} }
@ -19,6 +21,9 @@ export function ViewEvent(props: ViewEventProps) {
<div className="view-event-description"> <div className="view-event-description">
{props.description} {props.description}
</div> </div>
<FormDateRange
className="view-event-daterange"
/>
</main> </main>
) )
} }

View file

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

View file

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

View file

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

View file

@ -87,4 +87,8 @@ model Event {
postcard String? postcard String?
/// The description of the event. It will be parsed in Markdown! /// 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 ti ti ti x4"
"x1 x2 po x3 x4" "x1 x2 po x3 x4"
"x1 x2 de x3 x4" "x1 x2 de x3 x4"
"x1 x2 dr x3 x4"
; ;
grid-template-columns: 3fr 1fr 800px 1fr 3fr; grid-template-columns: 3fr 1fr 800px 1fr 3fr;
grid-template-rows: auto auto 1fr; grid-template-rows: auto auto 1fr auto;
row-gap: 4px; row-gap: 4px;
@ -25,3 +26,7 @@
.view-event-description { .view-event-description {
grid-area: de; grid-area: de;
} }
.view-event-daterange {
grid-area: dr;
}

View file

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