mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-22 14:44:21 +00:00
Make some progress
This commit is contained in:
parent
9d20277706
commit
28e85381b2
8 changed files with 115 additions and 27 deletions
13
components/FestaIcon.tsx
Normal file
13
components/FestaIcon.tsx
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { FontAwesomeIcon, FontAwesomeIconProps } from "@fortawesome/react-fontawesome";
|
||||
import classNames from "classnames";
|
||||
|
||||
export function FestaIcon(props: FontAwesomeIconProps) {
|
||||
const newClassName = classNames(props.className, "icon")
|
||||
|
||||
return (
|
||||
<FontAwesomeIcon
|
||||
{...props}
|
||||
className={newClassName}
|
||||
/>
|
||||
)
|
||||
}
|
|
@ -1,3 +1,61 @@
|
|||
export function FormEventList() {
|
||||
import classNames from "classnames";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import { HTMLProps } from "react";
|
||||
import { useMyEvents } from "../hooks/useMyEvents";
|
||||
import { Loading } from "./Loading";
|
||||
import { Event } from "@prisma/client";
|
||||
|
||||
|
||||
export function FormEventList(props: HTMLProps<HTMLFormElement>) {
|
||||
const {t} = useTranslation()
|
||||
const { data, error } = useMyEvents()
|
||||
|
||||
const newClassName = classNames(props.className, {
|
||||
"negative": error,
|
||||
})
|
||||
|
||||
let message: JSX.Element
|
||||
let contents: JSX.Element
|
||||
|
||||
if(error) {
|
||||
message = t("formEventListError")
|
||||
contents = (
|
||||
<div>
|
||||
<code>
|
||||
{JSON.stringify(error)}
|
||||
</code>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
else if(!data) {
|
||||
message = <Loading/>
|
||||
contents = <></>
|
||||
}
|
||||
else {
|
||||
console.debug(data)
|
||||
if(data.length === 0) {
|
||||
message = t("formEventListFirst")
|
||||
contents = (
|
||||
<div>zzz</div>
|
||||
)
|
||||
}
|
||||
else {
|
||||
message = t("formEventListAnother")
|
||||
contents = (
|
||||
<div>
|
||||
{data.map((event: Event) => <div><a href={`/events/slug`}>{event.name}</a></div>)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<form className={newClassName}>
|
||||
<p>
|
||||
{message}
|
||||
</p>
|
||||
{contents}
|
||||
</form>
|
||||
)
|
||||
}
|
|
@ -41,7 +41,7 @@ export function FormLoginTelegram({className, ...props}: HTMLProps<HTMLFormEleme
|
|||
"negative": error,
|
||||
})
|
||||
|
||||
let message: string
|
||||
let message: JSX.Element
|
||||
let contents: JSX.Element
|
||||
|
||||
if(error) {
|
||||
|
@ -56,7 +56,7 @@ export function FormLoginTelegram({className, ...props}: HTMLProps<HTMLFormEleme
|
|||
}
|
||||
else if(working) {
|
||||
message = t("formTelegramLoginWorking")
|
||||
contents = <div/>
|
||||
contents = <></>
|
||||
}
|
||||
else {
|
||||
message = t("formTelegramLoginDescription")
|
||||
|
|
19
components/Loading.tsx
Normal file
19
components/Loading.tsx
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { faAsterisk } from "@fortawesome/free-solid-svg-icons";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import { FestaIcon } from "./FestaIcon";
|
||||
|
||||
type LoadingProps = {
|
||||
text?: string
|
||||
}
|
||||
|
||||
export function Loading(props: LoadingProps) {
|
||||
const {t} = useTranslation()
|
||||
|
||||
return (
|
||||
<span>
|
||||
<FestaIcon icon={faAsterisk} spin/>
|
||||
|
||||
{props.text ?? t("genericLoading")}
|
||||
</span>
|
||||
)
|
||||
}
|
5
hooks/useMyEvents.ts
Normal file
5
hooks/useMyEvents.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import useSWR from "swr";
|
||||
|
||||
export function useMyEvents() {
|
||||
return useSWR("/api/events/mine")
|
||||
}
|
|
@ -4,6 +4,7 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
|
|||
import { LoginContext } from '../contexts/login';
|
||||
import { useDefinedContext } from '../utils/definedContext';
|
||||
import { FormLoginTelegram } from '../components/FormLoginTelegram';
|
||||
import { FormEventList } from '../components/FormEventList';
|
||||
|
||||
|
||||
export async function getStaticProps(context: NextPageContext) {
|
||||
|
@ -30,29 +31,9 @@ export default function PageIndex() {
|
|||
</h2>
|
||||
</hgroup>
|
||||
{login ?
|
||||
<div className="hero-action">
|
||||
<label htmlFor="input-name">
|
||||
<p>
|
||||
{t("eventsInputDescriptionFirst")}
|
||||
</p>
|
||||
</label>
|
||||
<form
|
||||
className="form-event-create"
|
||||
>
|
||||
<input
|
||||
id="input-name"
|
||||
placeholder={t("eventsInputName")}
|
||||
type="text"
|
||||
/>
|
||||
<input
|
||||
id="input-submit"
|
||||
type="submit"
|
||||
aria-label={t("eventsInputSubmitLabel")}
|
||||
value="→"
|
||||
className="square-40 positive"
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
<FormEventList
|
||||
className="hero-action"
|
||||
/>
|
||||
:
|
||||
<FormLoginTelegram
|
||||
className="hero-action"
|
||||
|
|
|
@ -10,5 +10,9 @@
|
|||
"eventsSubtitleAnother": "Cosa vuoi fare oggi?",
|
||||
"eventsInputName": "Nome evento",
|
||||
"eventsInputNamePlaceholder": "Festa a Festà",
|
||||
"eventsInputSubmitLabel": "Crea evento"
|
||||
"eventsInputSubmitLabel": "Crea evento",
|
||||
"genericLoading": "Caricamento...",
|
||||
"formEventListFirst": "Inserisci il nome del tuo primo evento qui sotto!",
|
||||
"formEventListAnother": "Questi sono gli eventi che hai creato:",
|
||||
"formEventListError": "Si è verificato il seguente errore durante il recupero dei tuoi eventi:"
|
||||
}
|
||||
|
|
|
@ -114,3 +114,11 @@ input.negative, button.negative {
|
|||
user-select: none;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.icon {
|
||||
filter: drop-shadow(1px 1px 1px var(--background));
|
||||
}
|
||||
|
||||
.icon.fa-pulse {
|
||||
filter: drop-shadow(1px 1px 1px var(--background));
|
||||
}
|
Loading…
Reference in a new issue