From 2697501b96aba29150686016ec15d3244533fe53 Mon Sep 17 00:00:00 2001 From: Varun Guleria Date: Thu, 2 Jan 2025 01:13:51 +0530 Subject: [PATCH] feat: dapp_modal_complete --- .../MarketplaceAppInfo/SocialLink.tsx | 18 +- ui/snippets/searchBar/SearchBar.tsx | 28 +- .../SearchBarSuggest/SearchBarSuggest.tsx | 10 +- .../SearchBarSuggest/SearchBarSuggestApp.tsx | 18 +- .../SearchBarSuggestExternalAppModal.tsx | 253 +++++++++++------- .../SearchBarSuggestItemButton.tsx | 40 +-- 6 files changed, 220 insertions(+), 147 deletions(-) diff --git a/ui/marketplace/MarketplaceAppInfo/SocialLink.tsx b/ui/marketplace/MarketplaceAppInfo/SocialLink.tsx index da3464f6d6..3d657b82df 100644 --- a/ui/marketplace/MarketplaceAppInfo/SocialLink.tsx +++ b/ui/marketplace/MarketplaceAppInfo/SocialLink.tsx @@ -11,9 +11,25 @@ export interface Props { icon: IconName; title: string; href?: string; + showIconsOnly?: boolean; } -const SocialLink = ({ href, icon, title }: Props) => { +const SocialLink = ({ href, icon, title, showIconsOnly }: Props) => { + if (showIconsOnly) { + return ( + + + + ); + } return ( { const { isOpen, onClose, onOpen } = useDisclosure(); - const modal = useDisclosure(); + const modal = useDisclosure(); const inputRef = React.useRef(null); const menuRef = React.useRef(null); const scrollRef = React.useRef(null); @@ -98,12 +99,15 @@ const SearchBar = ({ isHomepage }: Props) => { saveToRecentKeywords(searchTerm); onClose(); }, [ router.pathname, searchTerm, onClose ]); - const [dappDetails, setDappDetails] = React.useState(null); - const handleData = (data: MarketplaceAppOverview) => { - setDappDetails(data); - onClose(); - modal.onOpen(); - }; + const [ dappDetails, setDappDetails ] = React.useState(null); + const handleData = useCallback( + (data: MarketplaceAppOverview) => { + setDappDetails(data); + onClose(); + modal.onOpen(); + }, + [ setDappDetails, onClose, modal ], // Dependencies + ); const menuPaddingX = isMobile && !isHomepage ? 24 : 0; const calculateMenuWidth = React.useCallback(() => { @@ -182,7 +186,7 @@ const SearchBar = ({ isHomepage }: Props) => { searchTerm={ debouncedSearchTerm } onItemClick={ handleItemClick } containerId={ SCROLL_CONTAINER_ID } - handleData={handleData} + handleData={ handleData } /> ) } @@ -200,7 +204,7 @@ const SearchBar = ({ isHomepage }: Props) => { - + ); diff --git a/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggest.tsx b/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggest.tsx index 11db405969..e5c52146fd 100644 --- a/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggest.tsx +++ b/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggest.tsx @@ -5,6 +5,7 @@ import React from 'react'; import { scroller, Element } from 'react-scroll'; import type { SearchResultItem } from 'types/api/search'; +import type { MarketplaceAppOverview } from 'types/client/marketplace'; import type { ResourceError } from 'lib/api/resources'; import { useSettingsContext } from 'lib/contexts/settings'; @@ -19,13 +20,12 @@ import { getItemCategory, searchCategories } from 'ui/shared/search/utils'; import SearchBarSuggestApp from './SearchBarSuggestApp'; import SearchBarSuggestBlockCountdown from './SearchBarSuggestBlockCountdown'; import SearchBarSuggestItem from './SearchBarSuggestItem'; -import { MarketplaceAppOverview } from 'types/client/marketplace'; interface Props { query: UseQueryResult, ResourceError>; searchTerm: string; onItemClick: (event: React.MouseEvent) => void; containerId: string; - handleData :(data:MarketplaceAppOverview) => void; + handleData: (data: MarketplaceAppOverview) => void; } const SearchBarSuggest = ({ query, searchTerm, onItemClick, containerId, handleData }: Props) => { @@ -180,8 +180,10 @@ const SearchBarSuggest = ({ query, searchTerm, onItemClick, containerId, handleD addressFormat={ settingsContext?.addressFormat } /> )) } - { cat.id === 'app' && itemsGroups[cat.id]?.map((item, index) => - , + { cat.id === 'app' && itemsGroups[cat.id]?.map((item, index) => ( + + ), ) } ); diff --git a/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestApp.tsx b/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestApp.tsx index 16397bb4dc..474d014c06 100644 --- a/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestApp.tsx +++ b/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestApp.tsx @@ -5,11 +5,9 @@ import React from 'react'; import type { MarketplaceAppOverview } from 'types/client/marketplace'; import highlightText from 'lib/highlightText'; -import IconSvg from 'ui/shared/IconSvg'; -import SearchBarSuggestItemLink from './SearchBarSuggestItemLink'; -import SearchBarSuggestExternalAppModal from './SearchBarSuggestExternalAppModal'; import SearchBarSuggestItemButton from './SearchBarSuggestItemButton'; +import SearchBarSuggestItemLink from './SearchBarSuggestItemLink'; interface Props { data: MarketplaceAppOverview; isMobile: boolean | undefined; @@ -44,7 +42,6 @@ const SearchBarSuggestApp = ({ data, isMobile, searchTerm, onClick, handleData } > - {/* { data.external && } */} { data.description } - {/* { data.external && ( - - ) } */} ); })(); if (data.external) { return ( - - {content} + + { content } ); } diff --git a/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestExternalAppModal.tsx b/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestExternalAppModal.tsx index 814128255a..bca38b361c 100644 --- a/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestExternalAppModal.tsx +++ b/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestExternalAppModal.tsx @@ -2,14 +2,11 @@ import { Modal, ModalOverlay, ModalContent, - ModalHeader, ModalFooter, ModalBody, ModalCloseButton, Button, - useDisclosure, Box, - useColorModeValue, HStack, Image, VStack, @@ -17,27 +14,35 @@ import { Text, Tag, TagLabel, - IconButton + Flex, + Link, } from '@chakra-ui/react'; -import Stars from '../../../marketplace/Rating/Stars'; -import React, { useEffect } from 'react'; -import { MarketplaceAppOverview, MarketplaceAppSocialInfo } from 'types/client/marketplace'; +import React, { useCallback } from 'react'; + +import type { MarketplaceAppOverview } from 'types/client/marketplace'; + +import useIsMobile from 'lib/hooks/useIsMobile'; import IconSvg from 'ui/shared/IconSvg'; -import WebsiteLink from '../../../marketplace/MarketplaceAppInfo/WebsiteLink'; + +import useToast from '../../../../lib/hooks/useToast'; import SocialLink from '../../../marketplace/MarketplaceAppInfo/SocialLink'; import type { Props as SocialLinkProps } from '../../../marketplace/MarketplaceAppInfo/SocialLink'; +import WebsiteLink from '../../../marketplace/MarketplaceAppInfo/WebsiteLink'; +import Stars from '../../../marketplace/Rating/Stars'; type Props = { isModalOpen: boolean; onModalClose: () => void; dappDetails: MarketplaceAppOverview | null; }; const SOCIAL_LINKS: Array> = [ - { field: 'github', icon: "social/github_filled", title: 'Github' }, - { field: 'twitter', icon: "social/twitter_filled", title: 'X (ex-Twitter)' }, - { field: 'telegram', icon: "social/telegram_filled", title: 'Telegram' }, - { field: 'discord', icon: "social/discord_filled", title: 'Discord' }, + { field: 'github', icon: 'social/github_filled', title: 'Github' }, + { field: 'twitter', icon: 'social/twitter_filled', title: 'X (ex-Twitter)' }, + { field: 'telegram', icon: 'social/telegram_filled', title: 'Telegram' }, + { field: 'discord', icon: 'social/discord_filled', title: 'Discord' }, ]; -const SearchBarSuggestExternalAppModal =({isModalOpen, onModalClose, dappDetails}:Props)=> { +const SearchBarSuggestExternalAppModal = ({ isModalOpen, onModalClose, dappDetails }: Props) => { + const isMobile = Boolean(useIsMobile()); + const toast = useToast(); const socialLinks: Array = []; SOCIAL_LINKS.forEach((link) => { const href = dappDetails?.[link.field]; @@ -49,97 +54,151 @@ const SearchBarSuggestExternalAppModal =({isModalOpen, onModalClose, dappDetails } } }); - return ( - - - - {/* */} - - {dappDetails ? ( - - {/* App Header Section */} - - {`${dappDetails.title} - - - - - {dappDetails.title} + const handleCopy = useCallback(() => { + const urlToCopy = dappDetails?.site; + + navigator.clipboard + .writeText(urlToCopy || '') + .then(() => { + toast({ + status: 'success', + title: 'Copied to clipboard!', + }); + }) + .catch(() => { + toast({ + status: 'error', + title: 'URL Copy failed', + }); + }); + }, [ dappDetails?.site, toast ]); + + const launchApp = useCallback(() => { + const appUrl = dappDetails?.site; + window.open(appUrl, '_blank'); + }, [ dappDetails?.site ]); + + return ( + + + + + { dappDetails ? ( + + + { + + + + + { dappDetails.title } + + + + + + By { dappDetails.author } + + + + + + { dappDetails?.rating ? dappDetails?.rating : 0 } + { /* (5) */ } + + { /* + Rate it! + */ } + + + + + { /* */ } + + - - By {dappDetails.author} - - - - {2 - && - (<> - - - {2}(5) - - - Rate it! - - - )} - - - - - - - - - - {/* Description Section */} - - {dappDetails.description || "No description available."} - + + + - {/* Tags Section */} - {/* - {dappDetails.tags?.map((tag, index) => ( - - {tag} - - ))} - */} - - ) : ( - No details available for the selected app. - )} - - - - {dappDetails?.categories?.map((category, index) => ( - - {category} - - ))} + + { dappDetails.description || 'No description available.' } + + + ) : ( + No details available for the selected app. + ) } + + + { !isMobile && ( + + + { dappDetails?.categories?.map((category, index) => ( + + { category } + + )) } + + + { dappDetails?.site && } + { dappDetails && socialLinks?.map((link, index) => ( + + )) } - - (dappDetails && ) - (dappDetails && { socialLinks.map((link, index) => ) }) + + ) } + { isMobile && ( + + + { dappDetails?.categories?.map((category, index) => ( + + { category } + + )) } - - - - ); - -} + + { dappDetails?.site && } + { dappDetails && socialLinks?.map((link, index) => ( + + )) } + + + ) } + + + + ); + +}; export default React.memo(SearchBarSuggestExternalAppModal); diff --git a/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestItemButton.tsx b/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestItemButton.tsx index d7c8e5886c..80b9b1276c 100644 --- a/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestItemButton.tsx +++ b/ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestItemButton.tsx @@ -1,42 +1,46 @@ -import { chakra, useColorModeValue,Box } from '@chakra-ui/react'; -import React from 'react'; -import { MarketplaceAppOverview } from 'types/client/marketplace'; +import { useColorModeValue, Box } from '@chakra-ui/react'; +import React, { useCallback } from 'react'; + +import type { MarketplaceAppOverview } from 'types/client/marketplace'; type Props = { - data: any; + data: MarketplaceAppOverview; children: React.ReactNode; handleData: (data: MarketplaceAppOverview) => void; }; -const SearchBarSuggestItemButton = ({ data, children,handleData }: Props) => { - const handleClick = () => { - handleData(data); - }; - return( - { + const handleClick = useCallback(() => { + handleData(data); + }, [ data, handleData ]); + + const hoverBgColor = useColorModeValue('blue.50', 'gray.800'); + + return ( + - {children} + { children } - ) + ); }; export default SearchBarSuggestItemButton;