mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-22 22:54:22 +00:00
Improve (?) date visualization
This commit is contained in:
parent
3bb63cc9e6
commit
24c1ba8f54
4 changed files with 69 additions and 31 deletions
24
components/HumanDate.tsx
Normal file
24
components/HumanDate.tsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { useTranslation } from "next-i18next"
|
||||||
|
|
||||||
|
type HumanDateProps = {
|
||||||
|
date: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function HumanDate({date}: HumanDateProps) {
|
||||||
|
const {t} = useTranslation()
|
||||||
|
|
||||||
|
if(Number.isNaN(date.getTime())) {
|
||||||
|
return (
|
||||||
|
<span className="disabled">
|
||||||
|
{t("dateNaN")}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<time dateTime={date.toISOString()}>
|
||||||
|
{date.toLocaleString()}
|
||||||
|
</time>
|
||||||
|
)
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import { EditingContext } from "../../contexts/editing"
|
||||||
import { useDefinedContext } from "../../utils/definedContext"
|
import { useDefinedContext } from "../../utils/definedContext"
|
||||||
import { FestaIcon } from "../extensions/FestaIcon"
|
import { FestaIcon } from "../extensions/FestaIcon"
|
||||||
import { FormDateRange } from "../form/FormDateRange"
|
import { FormDateRange } from "../form/FormDateRange"
|
||||||
|
import { HumanDate } from "../HumanDate"
|
||||||
|
|
||||||
|
|
||||||
type EditableDateRangeProps = {
|
type EditableDateRangeProps = {
|
||||||
|
@ -15,9 +16,8 @@ type EditableDateRangeProps = {
|
||||||
export function EditableDateRange(props: EditableDateRangeProps) {
|
export function EditableDateRange(props: EditableDateRangeProps) {
|
||||||
const [editing,] = useDefinedContext(EditingContext)
|
const [editing,] = useDefinedContext(EditingContext)
|
||||||
|
|
||||||
const startDate = props.startProps
|
if(editing) {
|
||||||
|
return (
|
||||||
return editing ? (
|
|
||||||
<FormDateRange
|
<FormDateRange
|
||||||
preview={false}
|
preview={false}
|
||||||
icon={
|
icon={
|
||||||
|
@ -39,20 +39,33 @@ export function EditableDateRange(props: EditableDateRangeProps) {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
) : (
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const startTime = Date.parse(props.startProps.value!)
|
||||||
|
const endTime = Date.parse(props.endProps.value!)
|
||||||
|
|
||||||
|
if(Number.isNaN(startTime) && Number.isNaN(endTime)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const startDate = new Date(startTime)
|
||||||
|
const endDate = new Date(endTime)
|
||||||
|
|
||||||
|
return (
|
||||||
<FormDateRange
|
<FormDateRange
|
||||||
preview={true}
|
preview={true}
|
||||||
icon={
|
icon={
|
||||||
<FestaIcon icon={faClock}/>
|
<FestaIcon icon={faClock}/>
|
||||||
}
|
}
|
||||||
start={
|
start={
|
||||||
new Date(Date.parse(props.startProps.value!)).toLocaleString()
|
<HumanDate date={startDate}/>
|
||||||
}
|
}
|
||||||
connector={
|
connector={
|
||||||
<FestaIcon icon={faChevronRight}/>
|
<FestaIcon icon={faChevronRight}/>
|
||||||
}
|
}
|
||||||
end={
|
end={
|
||||||
new Date(Date.parse(props.endProps.value!)).toLocaleString()
|
<HumanDate date={endDate}/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
|
@ -51,8 +51,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 [startingAt, setStartingAt] = useState<string>(event.startingAt?.toISOString() ?? "")
|
||||||
const [endingAt, setEndingAt] = useState<string | null>(event.endingAt?.toISOString() ?? null)
|
const [endingAt, setEndingAt] = useState<string>(event.endingAt?.toISOString() ?? "")
|
||||||
|
|
||||||
const setPostcardBlob = useCallback(
|
const setPostcardBlob = useCallback(
|
||||||
(e: ChangeEvent<HTMLInputElement>) => {
|
(e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
@ -105,11 +105,11 @@ export default function PageEventDetail({event}: PageEventDetailProps) {
|
||||||
daterange={
|
daterange={
|
||||||
<EditableDateRange
|
<EditableDateRange
|
||||||
startProps={{
|
startProps={{
|
||||||
value: startingAt ?? undefined,
|
value: startingAt ?? "",
|
||||||
onChange: (e: ChangeEvent<HTMLInputElement>) => setStartingAt(e.target.value)
|
onChange: (e: ChangeEvent<HTMLInputElement>) => setStartingAt(e.target.value)
|
||||||
}}
|
}}
|
||||||
endProps={{
|
endProps={{
|
||||||
value: endingAt ?? undefined,
|
value: endingAt ?? "",
|
||||||
onChange: (e: ChangeEvent<HTMLInputElement>) => setEndingAt(e.target.value)
|
onChange: (e: ChangeEvent<HTMLInputElement>) => setEndingAt(e.target.value)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -31,5 +31,6 @@
|
||||||
"eventDetailsTitlePlaceholder": "Titolo",
|
"eventDetailsTitlePlaceholder": "Titolo",
|
||||||
"eventDetailsDescriptionPlaceholder": "Descrizione evento",
|
"eventDetailsDescriptionPlaceholder": "Descrizione evento",
|
||||||
"eventDetailsPostcardPlaceholder": "Cartolina",
|
"eventDetailsPostcardPlaceholder": "Cartolina",
|
||||||
"workInProgress": "Questa pagina è ancora in sviluppo e potrebbe contenere errori o testo inaspettato."
|
"workInProgress": "Questa pagina è ancora in sviluppo e potrebbe contenere errori o testo inaspettato.",
|
||||||
|
"dateNaN": "Non specificata"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue