From 20030d1bf21ff0ce9a0a95885abe88b79a0b4d04 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 21 Mar 2021 15:56:14 +0100 Subject: new toast design in code --- components/notificationsArea.tsx | 4 ++- components/toast.tsx | 63 ++++++++++++++++++++++++++-------------- pages/game.tsx | 4 ++- pages/login.tsx | 12 ++++++-- pages/register.tsx | 22 ++++++++++---- pages/user.tsx | 24 +++++++-------- 6 files changed, 85 insertions(+), 44 deletions(-) diff --git a/components/notificationsArea.tsx b/components/notificationsArea.tsx index 0a243e1..b427941 100644 --- a/components/notificationsArea.tsx +++ b/components/notificationsArea.tsx @@ -25,7 +25,9 @@ export function NotificationsArea(props: { useEffect(() => { if(messages > previousMessages) { - toast("Je hebt nieuwe meldingen!", "confirmation", ); + toast({ message: "Je hebt nieuwe meldingen!", + type: "confirmation", + icon: }); } setPreviousMessages(messages); diff --git a/components/toast.tsx b/components/toast.tsx index d774c96..91e67f7 100644 --- a/components/toast.tsx +++ b/components/toast.tsx @@ -23,6 +23,7 @@ function ToastArea(props: { function Toast(props: { text?: string + description?: string icon?: ReactNode children?: ReactNode type?: "normal"|"confirmation"|"error" @@ -35,7 +36,7 @@ function Toast(props: { return visible &&
{ props.children || -
+
{props.icon}
-

{props.text}

+

{props.text}

+

{props.description}

+
+
setVisibility(false)}> - +
}
} -export type toastType = (message: string, type: "confirmation"|"normal"|"error", icon?: ReactNode ) => void; +export type toastSettings = { + message: string, + description?: string, + type: "confirmation"|"normal"|"error", + icon?: ReactNode +} +export type toastType = (settings: toastSettings) => void; export var ToastContext = createContext<{ toast?: toastType }>({}); var toasts: Array = []; export function ToastContextWrapper(props: { children?: ReactNode }) { var [dummyState, rerender] = useState(false); - return { - toasts.push(); + return { + toasts.push(); rerender(!dummyState); } }}> { props.children } diff --git a/pages/game.tsx b/pages/game.tsx index f03933f..e44a7d9 100644 --- a/pages/game.tsx +++ b/pages/game.tsx @@ -61,7 +61,9 @@ function VoerGame(props: { }); props.io.on("resign", () => { - props.toast("Het potje is opgegeven", "normal", ); + props.toast({ message: "Het potje is opgegeven", + type: "normal", + icon: }); }); setIoListeners(true); diff --git a/pages/login.tsx b/pages/login.tsx index e33883f..abfca04 100644 --- a/pages/login.tsx +++ b/pages/login.tsx @@ -20,7 +20,9 @@ function submitLogin(event?: FormEvent, toast?: toastType) { if ( !formData.email || !formData.password ) { - toast("Vul alsjeblieft alle velden in!", "error", ); + toast({ message: "Vul alsjeblieft alle velden in!", + type: "error", + icon: }); return; } @@ -33,10 +35,14 @@ function submitLogin(event?: FormEvent, toast?: toastType) { .then(() => window.location.pathname = "/") .catch(error => { if (error.response.status === 401) { - toast("Verkeerde gebruikersnaam of wachtwoord!", "error", ); + toast({ message: "Verkeerde gebruikersnaam of wachtwoord!", + type: "error", + icon: }); return; } - toast("Er is iets fout gegaan", "error", ); + toast({ message: "Er is iets fout gegaan", + type: "error", + icon: }); }); } diff --git a/pages/register.tsx b/pages/register.tsx index b6db605..5c0e37b 100644 --- a/pages/register.tsx +++ b/pages/register.tsx @@ -22,7 +22,9 @@ function submitRegister(event?: FormEvent, toast?: toastType) { if ( !formData.username || !formData.email || !formData.password ) { - toast("Vul alsjeblieft alle velden in!", "error", ); + toast({ message: "Vul alsjeblieft alle velden in!", + type: "error", + icon: }); return; } @@ -38,18 +40,26 @@ function submitRegister(event?: FormEvent, toast?: toastType) { */ if ( formData.username.length < 3 || formData.username.length > 35 ) { - toast("Je gebruikersnaam moet tussen de 3 en 35 letters zijn!", "error", ); + toast({ message: "Ongeldige gebruikersnaam", + description: "Je gebruikersnaam moet tussen de 3 en 35 letters zijn", + type: "error", + icon: }); return; } if ( !validateEmail(formData.email) ) { - toast("Vul alsjeblieft een geldig email-adres in!", "error", ); + toast({ message: "Ongeldig email-adres", + type: "error", + icon: }); return; } //TODO: wachtwoord max 72 tekens ivm bcrypt if ( !formData.password.match(passwordRegex) ) { - toast("Je wachtwoord moet een hoofdletter, kleine letter en een getal bevatten!", "error", ); + toast({ message: "Ongeldig wachtwoord", + description: "Je wachtwoord moet een hoofdletter, kleine letter en een getal bevatten", + type: "error", + icon: }); return; } @@ -65,7 +75,9 @@ function submitRegister(event?: FormEvent, toast?: toastType) { window.location.pathname = "/"; }) .catch(error => { - toast("Er is iets fout gegaan", "error", ); + toast({ message: "Er is iets fout gegaan", + type: "error", + icon: }); console.log(error); }); } diff --git a/pages/user.tsx b/pages/user.tsx index dbad76e..ce870af 100644 --- a/pages/user.tsx +++ b/pages/user.tsx @@ -203,13 +203,13 @@ export default function AccountPage() { "endpoint": "/api/social/unblock", "action": `${user.username} gedeblokkeerd`, "relation": "none", - "icon": , + "icon": , } }[relation] || { "endpoint": "/api/social/block", "action": `${user.username} geblokkeerd`, "relation": "blocked", - "icon": , + "icon": , } axios.request({ @@ -219,9 +219,9 @@ export default function AccountPage() { data: { "id": user?.id } }) .then(() => { - toast(nextRelation.action, - "confirmation", - nextRelation.icon); + toast({ message: nextRelation.action, + type: "confirmation", + icon: nextRelation.icon }); setRelation(nextRelation.relation); }); }}/> @@ -245,25 +245,25 @@ export default function AccountPage() { "endpoint": "/api/social/remove", "action": `${user.username} succesvol verwijderd als vriend`, "relation": "none", - "icon": , + "icon": , }, "outgoing": { "endpoint": "/api/social/remove", "action": `Vriendschapsverzoek naar ${user.username} geannuleerd`, "relation": "none", - "icon": , + "icon": , }, "incoming": { "endpoint": "/api/social/accept", "action": `Vriendschapsverzoek van ${user.username} geaccepteerd`, "relation": "friends", - "icon": , + "icon": , }, }[relation] || { "endpoint": "/api/social/request", "action": `Vriendschapsverzoek gestuurd naar ${user.username}`, "relation": "outgoing", - "icon": , + "icon": , } axios.request({ @@ -273,9 +273,9 @@ export default function AccountPage() { data: { "id": user?.id } }) .then(() => { - toast(nextRelation.action, - "confirmation", - nextRelation.icon); + toast({ message: nextRelation.action, + type: "confirmation", + icon: nextRelation.icon }); setRelation(nextRelation.relation); }); }}/> -- cgit v1.2.3