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

Make some progress

This commit is contained in:
Steffo 2022-06-01 05:04:15 +02:00
parent 9d20277706
commit 28e85381b2
Signed by: steffo
GPG key ID: 6965406171929D01
8 changed files with 115 additions and 27 deletions

13
components/FestaIcon.tsx Normal file
View 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}
/>
)
}

View file

@ -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>
)
} }

View file

@ -41,7 +41,7 @@ export function FormLoginTelegram({className, ...props}: HTMLProps<HTMLFormEleme
"negative": error, "negative": error,
}) })
let message: string let message: JSX.Element
let contents: JSX.Element let contents: JSX.Element
if(error) { if(error) {
@ -56,7 +56,7 @@ export function FormLoginTelegram({className, ...props}: HTMLProps<HTMLFormEleme
} }
else if(working) { else if(working) {
message = t("formTelegramLoginWorking") message = t("formTelegramLoginWorking")
contents = <div/> contents = <></>
} }
else { else {
message = t("formTelegramLoginDescription") message = t("formTelegramLoginDescription")

19
components/Loading.tsx Normal file
View 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/>
&nbsp;
{props.text ?? t("genericLoading")}
</span>
)
}

5
hooks/useMyEvents.ts Normal file
View file

@ -0,0 +1,5 @@
import useSWR from "swr";
export function useMyEvents() {
return useSWR("/api/events/mine")
}

View file

@ -4,6 +4,7 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { LoginContext } from '../contexts/login'; import { LoginContext } from '../contexts/login';
import { useDefinedContext } from '../utils/definedContext'; import { useDefinedContext } from '../utils/definedContext';
import { FormLoginTelegram } from '../components/FormLoginTelegram'; import { FormLoginTelegram } from '../components/FormLoginTelegram';
import { FormEventList } from '../components/FormEventList';
export async function getStaticProps(context: NextPageContext) { export async function getStaticProps(context: NextPageContext) {
@ -30,29 +31,9 @@ export default function PageIndex() {
</h2> </h2>
</hgroup> </hgroup>
{login ? {login ?
<div className="hero-action"> <FormEventList
<label htmlFor="input-name"> className="hero-action"
<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>
: :
<FormLoginTelegram <FormLoginTelegram
className="hero-action" className="hero-action"

View file

@ -10,5 +10,9 @@
"eventsSubtitleAnother": "Cosa vuoi fare oggi?", "eventsSubtitleAnother": "Cosa vuoi fare oggi?",
"eventsInputName": "Nome evento", "eventsInputName": "Nome evento",
"eventsInputNamePlaceholder": "Festa a Festà", "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:"
} }

View file

@ -114,3 +114,11 @@ input.negative, button.negative {
user-select: none; user-select: none;
pointer-events: none; pointer-events: none;
} }
.icon {
filter: drop-shadow(1px 1px 1px var(--background));
}
.icon.fa-pulse {
filter: drop-shadow(1px 1px 1px var(--background));
}