From f4b22f9361ccaafc0b9d49c8f23e58997176f88d Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Wed, 31 Jul 2024 14:33:40 +0200 Subject: [PATCH] optimizing attestations --- .../Controls/GratitudeControl.tsx | 6 +- src/Components/Profile/Templates/TabsView.tsx | 76 +++++++++---------- src/Components/Templates/AttestationForm.tsx | 31 +++++--- src/Components/Templates/EmojiPicker.tsx | 2 +- 4 files changed, 66 insertions(+), 49 deletions(-) diff --git a/src/Components/Map/Subcomponents/Controls/GratitudeControl.tsx b/src/Components/Map/Subcomponents/Controls/GratitudeControl.tsx index 158b9619..a8f7109b 100644 --- a/src/Components/Map/Subcomponents/Controls/GratitudeControl.tsx +++ b/src/Components/Map/Subcomponents/Controls/GratitudeControl.tsx @@ -1,8 +1,11 @@ import { useNavigate } from "react-router-dom" +import { useAuth } from "../../../Auth"; export const GratitudeControl = () => { const navigate = useNavigate(); - return ( + const {isAuthenticated} = useAuth(); + + if(isAuthenticated) return (
{ @@ -22,4 +25,5 @@ export const GratitudeControl = () => {
) + else return (<>); } diff --git a/src/Components/Profile/Templates/TabsView.tsx b/src/Components/Profile/Templates/TabsView.tsx index cea2ea31..accb7928 100644 --- a/src/Components/Profile/Templates/TabsView.tsx +++ b/src/Components/Profile/Templates/TabsView.tsx @@ -5,7 +5,7 @@ import { ActionButton } from '../Subcomponents/ActionsButton' import { useCallback, useEffect, useRef, useState } from 'react' import { useAddFilterTag } from '../../Map/hooks/useFilter' import { Item, Tag } from 'utopia-ui/dist/types' -import { useNavigate } from 'react-router-dom' +import { Link, useNavigate } from 'react-router-dom' import { useItems } from '../../Map/hooks/useItems' import { useAssetApi } from '../../AppShell/hooks/useAssets' import { timeAgo } from '../../../Utils/TimeAgo' @@ -21,7 +21,7 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation const items = useItems(); const assetsApi = useAssetApi(); - const {user} = useAuth(); + const { user } = useAuth(); const getUserProfile = (id: string) => { return items.find(i => i.user_created.id === id && i.layer?.itemType.name === userType) @@ -79,41 +79,41 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation
- - {attestations.filter(a => a.to.some(t => t.directus_users_id == item.user_created.id)).map((a, i) => - - - - - - )} - + + {attestations + .filter(a => a.to.some(t => t.directus_users_id == item.user_created.id)) + .sort((a, b) => new Date(b.date_created).getTime() - new Date(a.date_created).getTime()) + .map((a, i) => ( + + + + + + ))} +
-
- {a.emoji} -
- -
-
{a.text}
- -
-
-
-
- Avatar Tailwind CSS Component -
-
-
-
{getUserProfile(a.user_created.id)?.name}
-
{timeAgo(a.date_created)}
- -
-
-
+
+ {a.emoji} +
+
+
{a.text}
+
+ +
+
+
+ Avatar Tailwind CSS Component +
+
+
+
{getUserProfile(a.user_created.id)?.name}
+
{timeAgo(a.date_created)}
+
+
+ +
@@ -123,7 +123,7 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation <> - updateActiveTab(3)} /> + updateActiveTab(3)} />
diff --git a/src/Components/Templates/AttestationForm.tsx b/src/Components/Templates/AttestationForm.tsx index 3b080e58..399eb9fc 100644 --- a/src/Components/Templates/AttestationForm.tsx +++ b/src/Components/Templates/AttestationForm.tsx @@ -7,6 +7,7 @@ import { Link, useNavigate } from 'react-router-dom'; import { useRef, useState } from 'react'; import { Item, ItemsApi } from '../../types'; import { useEffect } from 'react'; +import { toast } from 'react-toastify'; export const AttestationForm = ({api}:{api?:ItemsApi}) => { @@ -38,15 +39,27 @@ export const AttestationForm = ({api}:{api?:ItemsApi}) => { const sendAttestation = async () => { const to : Array = []; users?.map(u => to.push({ directus_users_id: u.user_created.id })); - console.log(to); - - api?.createItem && api.createItem({ - text: inputValue, - emoji: selectedEmoji, - color: selectedColor, - shape: selectedShape, - to: to - }).then(()=> navigate("/")) + + + api?.createItem && toast.promise( + api.createItem({ + text: inputValue, + emoji: selectedEmoji, + color: selectedColor, + shape: selectedShape, + to: to + }), { + pending: 'creating attestation ...', + success: 'Attestation created', + error: { + render({ data }) { + return `${data}` + }, + }, + }) + .then( () => navigate("/item/" + items.find(i => i.user_created.id===to[0].directus_users_id && i.layer?.itemType.name==="player")?.id+"?tab=2") + ) + } const [selectedEmoji, setSelectedEmoji] = useState('select badge'); diff --git a/src/Components/Templates/EmojiPicker.tsx b/src/Components/Templates/EmojiPicker.tsx index dcffc671..4f7f7be5 100644 --- a/src/Components/Templates/EmojiPicker.tsx +++ b/src/Components/Templates/EmojiPicker.tsx @@ -12,7 +12,7 @@ export const EmojiPicker = ({selectedEmoji, selectedColor, selectedShape, setSel '๐Ÿ“', 'โœ‰๏ธ', '๐Ÿงฉ','๐Ÿ’ก', '๐ŸŽ“', '๐Ÿ’ฌ', '๐Ÿ› ', '๐Ÿ’ป', '๐Ÿ•น', '๐Ÿ–จ', '๐Ÿš', '๐Ÿ›’', 'โšฝ๏ธ', '๐Ÿงต', '๐Ÿ‘€', '๐ŸŒฑ', - '๐Ÿ•', '๐Ÿ’ช', '๐ŸŽ', '๐ŸŽ‰', + '๐Ÿ•', '๐Ÿ’ช', '๐ŸŽ', '๐Ÿน', '๐Ÿฅ•', '๐Ÿฅ‡', '๐Ÿฅˆ', '๐Ÿฅ‰']; const shapes = ["squircle", "circle", "hexagon-2"];