From 9e95d6d9dc7d1388ceb676a9dd761691ab96f4a4 Mon Sep 17 00:00:00 2001 From: serhat Date: Tue, 6 Feb 2024 20:29:23 +0300 Subject: [PATCH] cleanup more --- web-app/.eslintrc.json | 16 +- web-app/src/components/ai/chat-message.tsx | 11 +- web-app/src/components/ai/markdown.tsx | 4 +- web-app/src/components/base/Avatar/index.tsx | 153 +++++---- .../components/base/BottomMenuDiv/index.tsx | 8 +- .../src/components/base/ButtonGroup/index.tsx | 4 +- web-app/src/components/base/List/index.tsx | 4 +- web-app/src/components/base/Popup/index.tsx | 6 +- .../src/components/base/SearchInput/index.tsx | 4 +- web-app/src/components/base/Tag/index.tsx | 4 +- web-app/src/components/base/Tooltip/index.tsx | 4 +- .../components/layout/base/Navbar/index.tsx | 13 +- .../layout/site/DiscoveryLayout/index.tsx | 17 +- .../layout/site/LandingLayout/index.tsx | 36 +- .../layout/site/SiteNavbar/index.tsx | 324 +++++++++--------- web-app/src/components/sections/AppLeft.tsx | 4 +- web-app/src/components/sections/AppRight.tsx | 5 +- .../IndexConversationContext.tsx | 6 +- .../IndexConversationHeader.tsx | 16 +- .../TabContainer/AccessControlTab.tsx | 5 +- .../TabContainer/ChatTab.tsx | 3 +- .../TabContainer/CreatorsTab.tsx | 11 +- .../TabContainer/IndexItemsTab.tsx | 42 ++- .../TabContainer/SettingsTab.tsx | 3 +- .../sections/IndexConversation/index.tsx | 2 - .../CreatorSettings/CreatorRule/index.tsx | 8 +- .../index-details/CreatorSettings/index.tsx | 6 +- .../index-details/IndexItemList/index.tsx | 4 +- .../index-details/IndexSettings/index.tsx | 3 +- .../site/index-details/LinkItem/index.tsx | 2 +- .../site/indexes/AskIndexes/index.tsx | 2 +- .../site/indexes/IndexItem/index.tsx | 7 +- .../site/indexes/NoIndexes/index.tsx | 4 +- .../components/site/indexes/NoLinks/index.tsx | 1 - .../site/indexes/NotFound/index.tsx | 33 +- .../site/landing/LandingSection7/index.tsx | 1 - .../modal/Common/ConfirmTransaction/index.tsx | 1 - .../site/modal/NewCreatorModal/index.tsx | 4 +- .../site/modal/OriginWarningModal/index.tsx | 85 ----- .../site/popup/IndexOperationsPopup/index.tsx | 4 +- web-app/src/context/APIContext.tsx | 2 +- web-app/src/context/AppContext.tsx | 14 +- web-app/src/context/AuthContext.tsx | 28 +- web-app/src/context/CeramicProvider.tsx | 2 +- web-app/src/hooks/store.ts | 5 - web-app/src/hooks/useAtBottom.tsx | 4 +- web-app/src/hooks/useEnterSubmit.tsx | 6 +- web-app/src/hooks/useLinks.tsx | 3 - web-app/src/hooks/useOwner.ts | 26 -- web-app/src/hooks/useRouteParams.ts | 4 +- web-app/src/hooks/useScrollRestoration.tsx | 4 +- web-app/src/services/api-service-new.ts | 10 +- web-app/src/services/lit-service.ts | 12 +- web-app/src/store/index.ts | 13 - web-app/src/store/slices/connectionSlice.ts | 74 ---- web-app/src/store/slices/profileSlice.ts | 28 -- web-app/src/utils/helper.ts | 9 +- 57 files changed, 436 insertions(+), 678 deletions(-) delete mode 100644 web-app/src/components/site/modal/OriginWarningModal/index.tsx delete mode 100644 web-app/src/hooks/store.ts delete mode 100644 web-app/src/hooks/useOwner.ts delete mode 100644 web-app/src/store/index.ts delete mode 100644 web-app/src/store/slices/connectionSlice.ts delete mode 100644 web-app/src/store/slices/profileSlice.ts diff --git a/web-app/.eslintrc.json b/web-app/.eslintrc.json index 8120727e..15893156 100644 --- a/web-app/.eslintrc.json +++ b/web-app/.eslintrc.json @@ -24,7 +24,7 @@ }, "rules": { "no-console": "off", - "implicit-arrow-linebreak": ["beside"], + "implicit-arrow-linebreak": "off", "linebreak-style": "off", "no-plusplus": "off", "no-unused-vars": "off", @@ -41,7 +41,13 @@ "argsIgnorePattern": "^_" } ], - "quotes": ["error", "double", { "allowTemplateLiterals": true }], + "quotes": [ + "error", + "double", + { + "allowTemplateLiterals": true + } + ], "no-tabs": "off", "max-classes-per-file": "off", "radix": 0, @@ -56,7 +62,6 @@ ], "consistent-return": "warn", "no-restricted-properties": "off", - "operator-linebreak": ["error", "after"], "no-use-before-define": "off", "no-mixed-spaces-and-tabs": "off", "no-param-reassign": "off", @@ -70,7 +75,10 @@ // Typescript Rules "@typescript-eslint/no-unused-vars": [ "off", - { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" } + { + "varsIgnorePattern": "^_", + "argsIgnorePattern": "^_" + } ], "@typescript-eslint/quotes": "off", "@typescript-eslint/return-await": "off", diff --git a/web-app/src/components/ai/chat-message.tsx b/web-app/src/components/ai/chat-message.tsx index cf6e7a57..634eb74e 100644 --- a/web-app/src/components/ai/chat-message.tsx +++ b/web-app/src/components/ai/chat-message.tsx @@ -3,6 +3,7 @@ import remarkBreaks from "remark-breaks"; import remarkGfm from "remark-gfm"; import remarkMath from "remark-math"; +import { useApp } from "@/context/AppContext"; import { ChatMessageActions } from "components/ai/chat-message-actions"; import { MemoizedReactMarkdown } from "components/ai/markdown"; import { CodeBlock } from "components/ai/ui/codeblock"; @@ -13,8 +14,6 @@ import Input from "components/base/Input"; import Col from "components/layout/base/Grid/Col"; import Flex from "components/layout/base/Grid/Flex"; import FlexRow from "components/layout/base/Grid/FlexRow"; -import { useAppSelector } from "hooks/store"; -import { selectProfile } from "store/slices/profileSlice"; export interface ChatMessageProps { message: Message; @@ -37,13 +36,13 @@ export function ChatMessage({ index, editingIndex, }: ChatMessageProps) { - const profile = useAppSelector(selectProfile); + const { viewedProfile } = useApp(); return ( {message.role === "user" ? ( - + ) : (
); }, - code({ inline, className, children, ...props }) { + code({ + inline, className, children, ...props +}) { if (children.length) { if (children[0] === "▍") { return ( diff --git a/web-app/src/components/ai/markdown.tsx b/web-app/src/components/ai/markdown.tsx index e27b9bee..f7e7f634 100644 --- a/web-app/src/components/ai/markdown.tsx +++ b/web-app/src/components/ai/markdown.tsx @@ -3,6 +3,6 @@ import ReactMarkdown, { Options } from "react-markdown"; export const MemoizedReactMarkdown: FC = memo( ReactMarkdown, - (prevProps, nextProps) => prevProps.children === nextProps.children && - prevProps.className === nextProps.className, + (prevProps, nextProps) => prevProps.children === nextProps.children + && prevProps.className === nextProps.className, ); diff --git a/web-app/src/components/base/Avatar/index.tsx b/web-app/src/components/base/Avatar/index.tsx index fd5adf77..b1849830 100644 --- a/web-app/src/components/base/Avatar/index.tsx +++ b/web-app/src/components/base/Avatar/index.tsx @@ -4,83 +4,92 @@ import { generateRandomColor, isSSR } from "utils/helper"; import { ShapeType } from "types"; import { Users } from "types/entity"; import { appConfig } from "config"; -import { ProfileState } from "store/slices/profileSlice"; -export interface AvatarProps extends React.DetailedHTMLProps, HTMLDivElement> { - size?: number; - user?: Users | ProfileState; - creatorRule?: any; - shape?: ShapeType; - hoverable?: boolean; - contentRatio?: number; - randomColor?: boolean; - bgColor?: string; +export interface AvatarProps + extends React.DetailedHTMLProps< + React.HTMLAttributes, + HTMLDivElement + > { + size?: number; + user?: Users; + creatorRule?: any; + shape?: ShapeType; + hoverable?: boolean; + contentRatio?: number; + randomColor?: boolean; + bgColor?: string; } -const Avatar = ( - { - size = 40, - user, - creatorRule, - children, - className, - style, - bgColor, - shape = "circle", - hoverable = false, - randomColor = false, - ...divProps - }: AvatarProps, -) => { - const maxLetters = size > 32 ? 4 : 2; - const [color, setColor] = useState(bgColor || "var(--main)"); - const getFontSize = () => size * (1 / maxLetters); - useEffect(() => { - if (!isSSR() && randomColor) { - setColor(generateRandomColor()); - } - }, []); +const Avatar = ({ + size = 40, + user, + creatorRule, + children, + className, + style, + bgColor, + shape = "circle", + hoverable = false, + randomColor = false, + ...divProps +}: AvatarProps) => { + const maxLetters = size > 32 ? 4 : 2; + const [color, setColor] = useState(bgColor || "var(--main)"); + const getFontSize = () => size * (1 / maxLetters); + useEffect(() => { + if (!isSSR() && randomColor) { + setColor(generateRandomColor()); + } + }, []); - return ( -
- { - user ? ( - user.avatar ? ( - profile_img - ) : ( - user.name ? user.name!.substring(0, 1).toUpperCase() : (user.id ? user.id.toString().slice(maxLetters * -1).toUpperCase() : "Y") - ) - ) : creatorRule ? ( - creatorRule.image ? ( - profile_img - ) : ( - (creatorRule.symbol || creatorRule.ensName)?.substring(0, 4).toUpperCase() - ) - ) : ( - typeof children !== "string" ? children : null - ) - } -
- ); + backgroundColor: color, + }} + > + {user ? ( + user.avatar ? ( + profile_img + ) : user.name ? ( + user.name!.substring(0, 1).toUpperCase() + ) : user.id ? ( + user.id + .toString() + .slice(maxLetters * -1) + .toUpperCase() + ) : ( + "Y" + ) + ) : creatorRule ? ( + creatorRule.image ? ( + profile_img + ) : ( + (creatorRule.symbol || creatorRule.ensName) + ?.substring(0, 4) + .toUpperCase() + ) + ) : typeof children !== "string" ? ( + children + ) : null} +
+ ); }; export default Avatar; diff --git a/web-app/src/components/base/BottomMenuDiv/index.tsx b/web-app/src/components/base/BottomMenuDiv/index.tsx index 59da7c1c..2a8ce9b6 100644 --- a/web-app/src/components/base/BottomMenuDiv/index.tsx +++ b/web-app/src/components/base/BottomMenuDiv/index.tsx @@ -98,8 +98,8 @@ const BottomMenuDiv = ( const handleMouseUp = useCallback((e: any) => { if (typeof e !== "boolean" && e) { setState((currentState) => { - const collapsed = currentState.maxHeight! < - currentState.originalHeight! * collapseThresholdForMinSize; + const collapsed = currentState.maxHeight! + < currentState.originalHeight! * collapseThresholdForMinSize; return { maxHeight: collapsed ? 0 : currentState.originalHeight!, transition, @@ -224,8 +224,8 @@ const BottomMenuDiv = ( className="modal-mobile-swiper-button"> {children} - : -
+ :
{children} diff --git a/web-app/src/components/base/ButtonGroup/index.tsx b/web-app/src/components/base/ButtonGroup/index.tsx index a240a73c..7d6ad96c 100644 --- a/web-app/src/components/base/ButtonGroup/index.tsx +++ b/web-app/src/components/base/ButtonGroup/index.tsx @@ -29,8 +29,8 @@ const ButtonGroup = ( className || "", ]) }>{ - children && - React.Children.map(children, (child: React.ReactElement) =>
{ + children + && React.Children.map(children, (child: React.ReactElement) =>
{ child }
) diff --git a/web-app/src/components/base/List/index.tsx b/web-app/src/components/base/List/index.tsx index 17caf565..b8604513 100644 --- a/web-app/src/components/base/List/index.tsx +++ b/web-app/src/components/base/List/index.tsx @@ -22,8 +22,8 @@ const List: FC = ({ return (
    - {data && - data.map((item, index) => ( + {data + && data.map((item, index) => ( { cancelHover.current = true; if ( - !closeOnMenuClick && - menuRef.current && - menuRef.current.contains(e.target) + !closeOnMenuClick + && menuRef.current + && menuRef.current.contains(e.target) ) { return; } diff --git a/web-app/src/components/base/SearchInput/index.tsx b/web-app/src/components/base/SearchInput/index.tsx index 790f71a5..e255804a 100644 --- a/web-app/src/components/base/SearchInput/index.tsx +++ b/web-app/src/components/base/SearchInput/index.tsx @@ -64,8 +64,8 @@ const SearchInput = ( {...inputProps} inputSize={"lg"} addOnBefore={} - addOnAfter={loading ? () : - (!disabled && showClear && query && ) + addOnAfter={loading ? () + : (!disabled && showClear && query && ) } onChange={handleChange} value={query} diff --git a/web-app/src/components/base/Tag/index.tsx b/web-app/src/components/base/Tag/index.tsx index d7bef627..05c9bba2 100644 --- a/web-app/src/components/base/Tag/index.tsx +++ b/web-app/src/components/base/Tag/index.tsx @@ -113,8 +113,8 @@ const Tag = ( onKeyDown={handleEnter} onBlur={handleClose} /> : value} - {removable && !editActive && -
    diff --git a/web-app/src/components/base/Tooltip/index.tsx b/web-app/src/components/base/Tooltip/index.tsx index 66005f2d..646b63b2 100644 --- a/web-app/src/components/base/Tooltip/index.tsx +++ b/web-app/src/components/base/Tooltip/index.tsx @@ -45,8 +45,8 @@ const Tooltip = ( > {children} { - visible && -
    + visible + &&
    {content}
    } diff --git a/web-app/src/components/layout/base/Navbar/index.tsx b/web-app/src/components/layout/base/Navbar/index.tsx index 40f02fbb..2aabdaf4 100644 --- a/web-app/src/components/layout/base/Navbar/index.tsx +++ b/web-app/src/components/layout/base/Navbar/index.tsx @@ -92,15 +92,18 @@ const Navbar = ({ return ( <> {isLanding && ( - Index Network is live on testnet. - +
    )}
    { setLeftSidebarOpen, rightSidebarOpen, setRightSidebarOpen, + setEditProfileModalVisible, + editProfileModalVisible, } = useApp(); const closeSidebars = () => { @@ -43,6 +46,12 @@ const DiscoveryLayout = ({ children, page }: DiscoveryLayoutProps) => { + {editProfileModalVisible && ( + setEditProfileModalVisible(false)} + /> + )}
    ); }; diff --git a/web-app/src/components/layout/site/LandingLayout/index.tsx b/web-app/src/components/layout/site/LandingLayout/index.tsx index 5c60214a..24d79d0f 100644 --- a/web-app/src/components/layout/site/LandingLayout/index.tsx +++ b/web-app/src/components/layout/site/LandingLayout/index.tsx @@ -1,21 +1,21 @@ -import React from "react"; -import Head from "next/head"; -import SiteNavbar from "../SiteNavbar"; -import SiteFooter from "../SiteFooter"; +// import React from "react"; +// import Head from "next/head"; +// import SiteNavbar from "../SiteNavbar"; +// import SiteFooter from "../SiteFooter"; -export interface LandingLayoutProps { - children: React.ReactNode; -} +// export interface LandingLayoutProps { +// children: React.ReactNode; +// } -const LandingLayout: React.FC = ({ children }) => ( - <> - - - - -
    {children}
    - - -); +// const LandingLayout: React.FC = ({ children }) => ( +// <> +// +// +// +// +//
    {children}
    +// +// +// ); -export default LandingLayout; +// export default LandingLayout; diff --git a/web-app/src/components/layout/site/SiteNavbar/index.tsx b/web-app/src/components/layout/site/SiteNavbar/index.tsx index aea56716..b30c35f6 100644 --- a/web-app/src/components/layout/site/SiteNavbar/index.tsx +++ b/web-app/src/components/layout/site/SiteNavbar/index.tsx @@ -1,172 +1,170 @@ -import Avatar from "components/base/Avatar"; -import Button from "components/base/Button"; -import Text from "components/base/Text"; -import Dropdown from "components/base/Dropdown"; -import DropdownMenuItem from "components/base/Dropdown/DropdownMenuItem"; +// import Avatar from "components/base/Avatar"; +// import Button from "components/base/Button"; +// import Text from "components/base/Text"; +// import Dropdown from "components/base/Dropdown"; +// import DropdownMenuItem from "components/base/Dropdown/DropdownMenuItem"; -import Flex from "components/layout/base/Grid/Flex"; -import { useTranslation } from "next-i18next"; -import React, { useCallback, useContext } from "react"; -import IconDisconnect from "components/base/Icon/IconDisconnect"; -import { AuthContext, AuthStatus, useAuth } from "@/context/AuthContext"; -import { useAppSelector } from "hooks/store"; -import { selectConnection } from "store/slices/connectionSlice"; -import { selectProfile } from "store/slices/profileSlice"; -import IconSettings from "components/base/Icon/IconSettings"; -import Navbar, { NavbarProps, NavbarMenu } from "components/layout/base/Navbar"; -import { useRouter } from "next/router"; -import IconHistory from "components/base/Icon/IconHistory"; -import { useApp } from "@/context/AppContext"; +// import Flex from "components/layout/base/Grid/Flex"; +// import { useTranslation } from "next-i18next"; +// import React, { useCallback, useContext } from "react"; +// import IconDisconnect from "components/base/Icon/IconDisconnect"; +// import { AuthContext, AuthStatus, useAuth } from "@/context/AuthContext"; +// import { useAppSelector } from "hooks/store"; -export interface LandingHeaderProps extends NavbarProps { - headerType: "public" | "user"; - isLanding?: boolean; -} +// import IconSettings from "components/base/Icon/IconSettings"; +// import Navbar, { NavbarProps, NavbarMenu } from "components/layout/base/Navbar"; +// import { useRouter } from "next/router"; +// import IconHistory from "components/base/Icon/IconHistory"; +// import { useApp } from "@/context/AppContext"; -const SiteNavbar = ({ - headerType = "user", - isLanding = false, - ...baseProps -}: LandingHeaderProps) => { - const { t } = useTranslation(["common", "components"]); +// export interface LandingHeaderProps extends NavbarProps { +// headerType: "public" | "user"; +// isLanding?: boolean; +// } - const { - setCreateModalVisible, - rightSidebarOpen, - setRightSidebarOpen, - setEditProfileModalVisible, - } = useApp(); - // const { - // did, - // // loading, - // } = useAppSelector(selectConnection); +// const SiteNavbar = ({ +// headerType = "user", +// isLanding = false, +// ...baseProps +// }: LandingHeaderProps) => { +// const { t } = useTranslation(["common", "components"]); - const profile = useAppSelector(selectProfile); - const { status } = useContext(AuthContext); // Consume AuthContext +// const { +// setCreateModalVisible, +// rightSidebarOpen, +// setRightSidebarOpen, +// setEditProfileModalVisible, +// } = useApp(); +// // const { +// // did, +// // // loading, +// // } = useAppSelector(selectConnection); - const authenticated = useAuth(); - const { connect, disconnect } = useContext(AuthContext); - const handleConnect = async () => { - try { - // await connect(); - } catch (err) { - console.log(err); - } - }; +// const { status } = useContext(AuthContext); // Consume AuthContext - const renderHeader = useCallback( - () => - headerType === "public" ? ( - - - {status === AuthStatus.LOADING && isLanding ? ( - - ) : ( - - )} - - - ) : ( - - {AuthStatus.CONNECTED ? ( - -
    - {" "} - -
    - - - { - setEditProfileModalVisible(true); - }} - > - - - - Profile Settings - - - - {/* - - - {t("common:settings")} - - */} - - - - - - {t("common:disconnect")} - - - - - } - > - - -
    - ) : ( - - - - )} -
    - ), - [headerType, baseProps, isLanding, t], - ); +// const authenticated = useAuth(); +// const { connect, disconnect } = useContext(AuthContext); +// const handleConnect = async () => { +// try { +// // await connect(); +// } catch (err) { +// console.log(err); +// } +// }; - return renderHeader(); -}; +// const renderHeader = useCallback( +// () => +// headerType === "public" ? ( +// +// +// {status === AuthStatus.LOADING && isLanding ? ( +// +// ) : ( +// +// )} +// +// +// ) : ( +// +// {AuthStatus.CONNECTED ? ( +// +//
    +// {" "} +// +//
    +// +// +// { +// setEditProfileModalVisible(true); +// }} +// > +// +// +// +// Profile Settings +// +// +// +// {/* +// +// +// {t("common:settings")} +// +// */} +// +// +// +// +// +// {t("common:disconnect")} +// +// +// +// +// } +// > +// +// +//
    +// ) : ( +// +// +// +// )} +//
    +// ), +// [headerType, baseProps, isLanding, t], +// ); -export default SiteNavbar; +// return renderHeader(); +// }; + +// export default SiteNavbar; diff --git a/web-app/src/components/sections/AppLeft.tsx b/web-app/src/components/sections/AppLeft.tsx index 3552b60c..07fad66d 100644 --- a/web-app/src/components/sections/AppLeft.tsx +++ b/web-app/src/components/sections/AppLeft.tsx @@ -78,8 +78,8 @@ const AppLeft = () => { ) : ( <>
    - {viewedProfile?.name || - (viewedProfile?.id + {viewedProfile?.name + || (viewedProfile?.id ? maskDID(viewedProfile?.id!) : "")}
    diff --git a/web-app/src/components/sections/AppRight.tsx b/web-app/src/components/sections/AppRight.tsx index e43ea086..db1aa2d0 100644 --- a/web-app/src/components/sections/AppRight.tsx +++ b/web-app/src/components/sections/AppRight.tsx @@ -10,8 +10,9 @@ import { useApp } from "@/context/AppContext"; import Soon from "components/site/indexes/Soon"; const AppRight = () => { - const { setRightSidebarOpen, rightSidebarOpen, rightTabKey, setRightTabKey } = - useApp(); + const { + setRightSidebarOpen, rightSidebarOpen, rightTabKey, setRightTabKey, +} = useApp(); return ( { } // DEBUG - let response = await api.getItems(viewedIndex.id, itemParams); + const response = await api.getItems(viewedIndex.id, itemParams); // if (itemParams.query) { // response = { // items: [], @@ -88,8 +88,8 @@ export const IndexConversationProvider = ({ children }: { children: any }) => { cursor: response.endCursor, })); } - } catch (error) { - console.error("Error fetching index links", error); + } catch (err: any) { + console.error("Error fetching index links", err); setError(error); } finally { // setLoading(false); diff --git a/web-app/src/components/sections/IndexConversation/IndexConversationHeader.tsx b/web-app/src/components/sections/IndexConversation/IndexConversationHeader.tsx index b71aba1e..bb022158 100644 --- a/web-app/src/components/sections/IndexConversation/IndexConversationHeader.tsx +++ b/web-app/src/components/sections/IndexConversation/IndexConversationHeader.tsx @@ -22,8 +22,9 @@ export const IndexConversationHeader: React.FC = () => { const { session } = useAuth(); const { apiService: api } = useApi(); const [titleLoading, setTitleLoading] = useState(false); - const { viewedIndex, viewedProfile, setViewedIndex, indexes, setIndexes } = - useApp(); + const { + viewedIndex, viewedProfile, setViewedIndex, indexes, setIndexes, +} = useApp(); // if (!viewedIndex || !viewedProfile) return null; @@ -69,8 +70,7 @@ export const IndexConversationHeader: React.FC = () => { setViewedIndex(updatedIndex); setIndexes( indexes.map((index) => - index.id === updatedIndex.id ? updatedIndex : index, - ), + (index.id === updatedIndex.id ? updatedIndex : index)), ); }, [viewedIndex, viewedProfile, api, setViewedIndex, indexes, setIndexes], @@ -92,10 +92,10 @@ export const IndexConversationHeader: React.FC = () => { fontWeight={500} element="span" > - {viewedIndex?.ownerDID?.name || - (viewedIndex?.ownerDID && - maskDID(viewedIndex?.ownerDID?.id!)) || - ""} + {viewedIndex?.ownerDID?.name + || (viewedIndex?.ownerDID + && maskDID(viewedIndex?.ownerDID?.id!)) + || ""} } diff --git a/web-app/src/components/sections/IndexConversation/TabContainer/AccessControlTab.tsx b/web-app/src/components/sections/IndexConversation/TabContainer/AccessControlTab.tsx index f368acbf..37821fd0 100644 --- a/web-app/src/components/sections/IndexConversation/TabContainer/AccessControlTab.tsx +++ b/web-app/src/components/sections/IndexConversation/TabContainer/AccessControlTab.tsx @@ -2,13 +2,10 @@ import Col from "@/components/layout/base/Grid/Col"; import FlexRow from "@/components/layout/base/Grid/FlexRow"; import { useApi } from "@/context/APIContext"; import { useApp } from "@/context/AppContext"; -import AskIndexes from "@/components/site/indexes/AskIndexes"; -import NoLinks from "@/components/site/indexes/NoLinks"; import Soon from "@/components/site/indexes/Soon"; import { useRole } from "@/hooks/useRole"; import { useRouteParams } from "@/hooks/useRouteParams"; -import { IndexLink } from "@/types/entity"; -import React, { useCallback, useEffect, useState } from "react"; +import React from "react"; import { useIndexConversation } from "../IndexConversationContext"; export default function AccessControlTabSection() { diff --git a/web-app/src/components/sections/IndexConversation/TabContainer/ChatTab.tsx b/web-app/src/components/sections/IndexConversation/TabContainer/ChatTab.tsx index 25b99369..5753cf91 100644 --- a/web-app/src/components/sections/IndexConversation/TabContainer/ChatTab.tsx +++ b/web-app/src/components/sections/IndexConversation/TabContainer/ChatTab.tsx @@ -29,7 +29,6 @@ export default function ChatTabSection() { return chatID ? ( ) : null; - } else { - return {}} contextMessage="your responses" />; } + return {}} contextMessage="your responses" />; } diff --git a/web-app/src/components/sections/IndexConversation/TabContainer/CreatorsTab.tsx b/web-app/src/components/sections/IndexConversation/TabContainer/CreatorsTab.tsx index 387c03e6..768e7df3 100644 --- a/web-app/src/components/sections/IndexConversation/TabContainer/CreatorsTab.tsx +++ b/web-app/src/components/sections/IndexConversation/TabContainer/CreatorsTab.tsx @@ -4,14 +4,11 @@ import FlexRow from "@/components/layout/base/Grid/FlexRow"; import { useApi } from "@/context/APIContext"; import { useApp } from "@/context/AppContext"; import CreatorSettings from "@/components/site/index-details/CreatorSettings"; -import AskIndexes from "@/components/site/indexes/AskIndexes"; -import NoLinks from "@/components/site/indexes/NoLinks"; import { useRole } from "@/hooks/useRole"; import { useRouteParams } from "@/hooks/useRouteParams"; -import { IndexLink } from "@/types/entity"; import { LitContracts } from "@lit-protocol/contracts-sdk"; import { ethers } from "ethers"; -import React, { useCallback, useEffect, useState } from "react"; +import React from "react"; export default function CreatorsTabSection({ noLinks }: { noLinks?: boolean }) { const { id: indexID } = useRouteParams(); @@ -30,14 +27,12 @@ export default function CreatorsTabSection({ noLinks }: { noLinks?: boolean }) { const previousCollabAction = litContracts.utils.getBytesFromMultihash( viewedIndex.collabAction!, ); - const addPermissionTx = - await litContracts.pkpPermissionsContract.write.addPermittedAction( + const addPermissionTx = await litContracts.pkpPermissionsContract.write.addPermittedAction( tokenId, newCollabAction, [], ); - const removePermissionTx = - await litContracts.pkpPermissionsContract.write.removePermittedAction( + const removePermissionTx = await litContracts.pkpPermissionsContract.write.removePermittedAction( tokenId, previousCollabAction, ); diff --git a/web-app/src/components/sections/IndexConversation/TabContainer/IndexItemsTab.tsx b/web-app/src/components/sections/IndexConversation/TabContainer/IndexItemsTab.tsx index 995e9569..f17ed90f 100644 --- a/web-app/src/components/sections/IndexConversation/TabContainer/IndexItemsTab.tsx +++ b/web-app/src/components/sections/IndexConversation/TabContainer/IndexItemsTab.tsx @@ -39,29 +39,27 @@ export default function IndexItemsTabSection() { if (!api || !viewedIndex) return; setLoading(true); - for (const url of urls) { - try { - const createdLink = await api.crawlLink(url); - if (!createdLink) { - throw new Error("Error creating link"); - } - const createdItem = await api.createItem( - viewedIndex.id, - createdLink.id, - ); - console.log("create item", createdItem); - if (!createdItem) { - throw new Error("Error creating item"); - } - setItemsState({ - items: [createdItem, ...itemsState.items], - cursor: itemsState.cursor, - }); - } catch (error) { - console.error("Error adding link", error); - } finally { - setLoading(false); + try { + const createdLink = await api.crawlLink(urls[0]); + if (!createdLink) { + throw new Error("Error creating link"); + } + const createdItem = await api.createItem( + viewedIndex.id, + createdLink.id, + ); + console.log("create item", createdItem); + if (!createdItem) { + throw new Error("Error creating item"); } + setItemsState({ + items: [createdItem, ...itemsState.items], + cursor: itemsState.cursor, + }); + } catch (error) { + console.error("Error adding link", error); + } finally { + setLoading(false); } }, [api, viewedIndex, setItemsState, setLoading], diff --git a/web-app/src/components/sections/IndexConversation/TabContainer/SettingsTab.tsx b/web-app/src/components/sections/IndexConversation/TabContainer/SettingsTab.tsx index 95609a34..5355b695 100644 --- a/web-app/src/components/sections/IndexConversation/TabContainer/SettingsTab.tsx +++ b/web-app/src/components/sections/IndexConversation/TabContainer/SettingsTab.tsx @@ -4,8 +4,7 @@ import Text from "components/base/Text"; import Col from "components/layout/base/Grid/Col"; import Flex from "components/layout/base/Grid/Flex"; import FlexRow from "components/layout/base/Grid/FlexRow"; -import React, { useEffect, useState } from "react"; -import LitService from "../../../../services/lit-service"; +import React, { useState } from "react"; export interface IndexSettingsTabSectionProps {} diff --git a/web-app/src/components/sections/IndexConversation/index.tsx b/web-app/src/components/sections/IndexConversation/index.tsx index af1ee856..6a6e28b5 100644 --- a/web-app/src/components/sections/IndexConversation/index.tsx +++ b/web-app/src/components/sections/IndexConversation/index.tsx @@ -1,5 +1,3 @@ -import { useEffect } from "react"; - import Flex from "components/layout/base/Grid/Flex"; import { useApp } from "@/context/AppContext"; import Head from "next/head"; diff --git a/web-app/src/components/site/index-details/CreatorSettings/CreatorRule/index.tsx b/web-app/src/components/site/index-details/CreatorSettings/CreatorRule/index.tsx index 15620f38..28212d11 100644 --- a/web-app/src/components/site/index-details/CreatorSettings/CreatorRule/index.tsx +++ b/web-app/src/components/site/index-details/CreatorSettings/CreatorRule/index.tsx @@ -47,10 +47,10 @@ const CreatorRule = ({ rule, handleRemove }: CreatorRuleProps) => (
    - {rule.name || - rule.ensName || - (rule.walletAddress && maskAddress(rule.walletAddress)) || - (rule.contractAddress && maskAddress(rule.contractAddress))} + {rule.name + || rule.ensName + || (rule.walletAddress && maskAddress(rule.walletAddress)) + || (rule.contractAddress && maskAddress(rule.contractAddress))}
    = ({ - {conditions && - conditions.map((c: any, i: any) => ( + {conditions + && conditions.map((c: any, i: any) => ( handleRemove(i)} diff --git a/web-app/src/components/site/index-details/IndexItemList/index.tsx b/web-app/src/components/site/index-details/IndexItemList/index.tsx index c15fde17..b362676c 100644 --- a/web-app/src/components/site/index-details/IndexItemList/index.tsx +++ b/web-app/src/components/site/index-details/IndexItemList/index.tsx @@ -1,10 +1,10 @@ import React from "react"; import List from "components/base/List"; import InfiniteScroll from "react-infinite-scroller"; -import LinkItem from "../LinkItem"; -import NoLinks from "../../indexes/NoLinks"; import { IndexItem } from "types/entity"; import { useRole } from "hooks/useRole"; +import LinkItem from "../LinkItem"; +import NoLinks from "../../indexes/NoLinks"; export interface IndexItemListProps { search: string; diff --git a/web-app/src/components/site/index-details/IndexSettings/index.tsx b/web-app/src/components/site/index-details/IndexSettings/index.tsx index fabad8ba..2127edcd 100644 --- a/web-app/src/components/site/index-details/IndexSettings/index.tsx +++ b/web-app/src/components/site/index-details/IndexSettings/index.tsx @@ -1,11 +1,10 @@ -import React, { useEffect, useState } from "react"; +import React, { useState } from "react"; import Header from "components/base/Header"; import Text from "components/base/Text"; import Col from "components/layout/base/Grid/Col"; import FlexRow from "components/layout/base/Grid/FlexRow"; import Flex from "components/layout/base/Grid/Flex"; import CopyInput from "components/base/CopyInput"; -import LitService from "../../../../services/lit-service"; export interface IndexSettingsProps {} diff --git a/web-app/src/components/site/index-details/LinkItem/index.tsx b/web-app/src/components/site/index-details/LinkItem/index.tsx index 983d93a9..b089cdf3 100644 --- a/web-app/src/components/site/index-details/LinkItem/index.tsx +++ b/web-app/src/components/site/index-details/LinkItem/index.tsx @@ -10,8 +10,8 @@ import IndexDetailItemPopup from "components/site/popup/IndexDetailItemPopup"; import { IndexItem } from "types/entity"; import moment from "moment"; import sanitize from "sanitize-html"; -import cm from "./style.module.scss"; import { useRole } from "hooks/useRole"; +import cm from "./style.module.scss"; // TODO: data prop will be Index object export interface LinkItemProps { diff --git a/web-app/src/components/site/indexes/AskIndexes/index.tsx b/web-app/src/components/site/indexes/AskIndexes/index.tsx index 90841785..b26e0d30 100644 --- a/web-app/src/components/site/indexes/AskIndexes/index.tsx +++ b/web-app/src/components/site/indexes/AskIndexes/index.tsx @@ -11,7 +11,7 @@ import { ButtonScrollToBottom } from "components/ai/button-scroll-to-bottom"; import { API_ENDPOINTS } from "utils/constants"; import Flex from "components/layout/base/Grid/Flex"; import { maskDID } from "utils/helper"; -import { DiscoveryType, useApp } from "@/context/AppContext"; +import { useApp } from "@/context/AppContext"; import { ChatScrollAnchor } from "components/ai/chat-scroll-anchor"; import NoIndexesChat from "components/ai/no-indexes"; import { AuthContext } from "@/context/AuthContext"; diff --git a/web-app/src/components/site/indexes/IndexItem/index.tsx b/web-app/src/components/site/indexes/IndexItem/index.tsx index e921abd9..d71f8d1c 100644 --- a/web-app/src/components/site/indexes/IndexItem/index.tsx +++ b/web-app/src/components/site/indexes/IndexItem/index.tsx @@ -12,7 +12,6 @@ import sanitize from "sanitize-html"; import cc from "classcat"; import { maskDID } from "utils/helper"; import Link from "next/link"; -import { useRouter } from "next/navigation"; import cm from "./style.module.scss"; export interface IndexItemProps { @@ -21,10 +20,10 @@ export interface IndexItemProps { onClick?(): Promise; } -const IndexItem: React.VFC = ({ index, selected, onClick }) => { +const IndexItem: React.VFC = ({ index, selected, onClick }) => // const router = useRouter(); // const { did } = router.query; - return ( + ( = ({ index, selected, onClick }) => { ); -}; - export default IndexItem; diff --git a/web-app/src/components/site/indexes/NoIndexes/index.tsx b/web-app/src/components/site/indexes/NoIndexes/index.tsx index fc177791..63cf70a5 100644 --- a/web-app/src/components/site/indexes/NoIndexes/index.tsx +++ b/web-app/src/components/site/indexes/NoIndexes/index.tsx @@ -3,15 +3,15 @@ import Header from "components/base/Header"; import Col from "components/layout/base/Grid/Col"; import Row from "components/layout/base/Grid/Row"; import React from "react"; -import { useOwner } from "hooks/useOwner"; import { useApp } from "@/context/AppContext"; +import { useRole } from "@/hooks/useRole"; export interface NoIndexesProps { tabKey?: string; } const NoIndexes: React.VFC = ({ tabKey }) => { - const { isOwner } = useOwner(); + const { isOwner } = useRole(); const { setCreateModalVisible } = useApp(); return ( diff --git a/web-app/src/components/site/indexes/NoLinks/index.tsx b/web-app/src/components/site/indexes/NoLinks/index.tsx index b7691268..ab3ecfda 100644 --- a/web-app/src/components/site/indexes/NoLinks/index.tsx +++ b/web-app/src/components/site/indexes/NoLinks/index.tsx @@ -3,7 +3,6 @@ import Col from "components/layout/base/Grid/Col"; import Row from "components/layout/base/Grid/Row"; import { useApp } from "@/context/AppContext"; import React from "react"; -import { Indexes } from "types/entity"; export interface NoLinksProps { search?: string; diff --git a/web-app/src/components/site/indexes/NotFound/index.tsx b/web-app/src/components/site/indexes/NotFound/index.tsx index 04085c85..dc5703b9 100644 --- a/web-app/src/components/site/indexes/NotFound/index.tsx +++ b/web-app/src/components/site/indexes/NotFound/index.tsx @@ -1,14 +1,10 @@ import Header from "components/base/Header"; import Col from "components/layout/base/Grid/Col"; import Flex from "components/layout/base/Grid/Flex"; -import FlexRow from "components/layout/base/Grid/FlexRow"; -import Row from "components/layout/base/Grid/Row"; import Image from "next/image"; import React from "react"; - -const NotFound: React.FC = ({ -}) => ( +const NotFound: React.FC = () => ( - - - Not found + + Not found -
    {`Page not found.`}
    +
    {`Page not found.`}
    diff --git a/web-app/src/components/site/landing/LandingSection7/index.tsx b/web-app/src/components/site/landing/LandingSection7/index.tsx index 9e66b92d..2a7c7f44 100644 --- a/web-app/src/components/site/landing/LandingSection7/index.tsx +++ b/web-app/src/components/site/landing/LandingSection7/index.tsx @@ -3,7 +3,6 @@ import Header from "components/base/Header"; import Input from "components/base/Input"; import Flex from "components/layout/base/Grid/Flex"; import { useState } from "react"; -import toast from "react-hot-toast"; import LandingSection from "../LandingSection"; const LandingSection7 = () => { diff --git a/web-app/src/components/site/modal/Common/ConfirmTransaction/index.tsx b/web-app/src/components/site/modal/Common/ConfirmTransaction/index.tsx index 2c50bbf7..e31182e9 100644 --- a/web-app/src/components/site/modal/Common/ConfirmTransaction/index.tsx +++ b/web-app/src/components/site/modal/Common/ConfirmTransaction/index.tsx @@ -7,7 +7,6 @@ import Row from "components/layout/base/Grid/Row"; import Header from "components/base/Header"; import Flex from "components/layout/base/Grid/Flex"; - const ConfirmTransaction = ({ handleCancel, ...modalProps }: any) => { const handleClose = () => { modalProps.onClose?.(); diff --git a/web-app/src/components/site/modal/NewCreatorModal/index.tsx b/web-app/src/components/site/modal/NewCreatorModal/index.tsx index f8630aa2..d092b976 100644 --- a/web-app/src/components/site/modal/NewCreatorModal/index.tsx +++ b/web-app/src/components/site/modal/NewCreatorModal/index.tsx @@ -54,11 +54,11 @@ const NewCreatorModal = ({ <> {activeForm === "nft-options" ? ( <>TBI - ) : // handleFormState("initial")} // > - activeForm === "new-nft" ? ( + : activeForm === "new-nft" ? ( <> ) : activeForm === "individual-wallet" ? ( <> TBI diff --git a/web-app/src/components/site/modal/OriginWarningModal/index.tsx b/web-app/src/components/site/modal/OriginWarningModal/index.tsx deleted file mode 100644 index 936d497e..00000000 --- a/web-app/src/components/site/modal/OriginWarningModal/index.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import Text from "components/base/Text"; -import Modal, { ModalProps } from "components/base/Modal"; -import Row from "components/layout/base/Grid/Row"; -import React from "react"; -import Col from "components/layout/base/Grid/Col"; -import Header from "components/base/Header"; -import Flex from "components/layout/base/Grid/Flex"; -import Button from "components/base/Button"; -import Link from "next/link"; - -import { useAppDispatch } from "hooks/store"; -import { setOriginNFTModalVisible } from "store/slices/connectionSlice"; - -export interface OriginWarningModalProps - extends Omit { - visible: boolean; -} - -const OriginWarningModal = ({ ...modalProps }: OriginWarningModalProps) => { - const dispatch = useAppDispatch(); - - const handleClose = () => { - dispatch(setOriginNFTModalVisible(false)); - }; - return ( - - - - - - - To access the beta version, please fill out a short form. -
    - Once done, we will send you an NFT for access. -
    -
    -
    -
    - - - - - - - - - - -
    - - } - header={
    We should meet!
    } - /> - ); -}; - -export default OriginWarningModal; diff --git a/web-app/src/components/site/popup/IndexOperationsPopup/index.tsx b/web-app/src/components/site/popup/IndexOperationsPopup/index.tsx index 166411f8..e0311111 100644 --- a/web-app/src/components/site/popup/IndexOperationsPopup/index.tsx +++ b/web-app/src/components/site/popup/IndexOperationsPopup/index.tsx @@ -36,8 +36,8 @@ const IndexOperationsPopup: React.FC = ({ - {index?.roles?.owner && - (index?.did?.owned ? ( + {index?.roles?.owner + && (index?.did?.owned ? ( <> diff --git a/web-app/src/context/APIContext.tsx b/web-app/src/context/APIContext.tsx index fb401701..c315b76b 100644 --- a/web-app/src/context/APIContext.tsx +++ b/web-app/src/context/APIContext.tsx @@ -8,8 +8,8 @@ import { useState, } from "react"; import ApiService from "services/api-service-new"; -import { AuthContext, AuthStatus } from "./AuthContext"; import { useRouteParams } from "@/hooks/useRouteParams"; +import { AuthContext } from "./AuthContext"; export const defaultAPIContext = { apiService: ApiService.getInstance(), diff --git a/web-app/src/context/AppContext.tsx b/web-app/src/context/AppContext.tsx index 58f5938b..0abe36a5 100644 --- a/web-app/src/context/AppContext.tsx +++ b/web-app/src/context/AppContext.tsx @@ -1,10 +1,8 @@ import { useApi } from "@/context/APIContext"; import { useAuth } from "@/context/AuthContext"; import { useRouteParams } from "@/hooks/useRouteParams"; -import litService from "@/services/lit-service"; import ConfirmTransaction from "components/site/modal/Common/ConfirmTransaction"; import CreateModal from "components/site/modal/CreateModal"; -import EditProfileModal from "components/site/modal/EditProfileModal"; import { useRouter } from "next/navigation"; import { ReactNode, @@ -52,6 +50,7 @@ export interface AppContextValue { setLeftSidebarOpen: (visible: boolean) => void; rightSidebarOpen: boolean; setRightSidebarOpen: (visible: boolean) => void; + editProfileModalVisible: boolean; setEditProfileModalVisible: (visible: boolean) => void; updateIndex: (index: Indexes) => void; updateUserIndexState: (index: Indexes, value: boolean) => void; @@ -84,8 +83,7 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => { const [userProfile, setUserProfile] = useState(); const [createModalVisible, setCreateModalVisible] = useState(false); const [editProfileModalVisible, setEditProfileModalVisible] = useState(false); - const [transactionApprovalWaiting, setTransactionApprovalWaiting] = - useState(false); + const [transactionApprovalWaiting, setTransactionApprovalWaiting] = useState(false); const [leftSidebarOpen, setLeftSidebarOpen] = useState(false); const [rightSidebarOpen, setRightSidebarOpen] = useState(false); const [rightTabKey, setRightTabKey] = useState("history"); @@ -134,7 +132,6 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => { setCreateModalVisible(false); setTransactionApprovalWaiting(true); try { - debugger; if (!api) return; const doc = await api.createIndex(title); if (!doc) { @@ -272,6 +269,7 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => { handleCreate, loading, handleTransactionCancel, + editProfileModalVisible, chatID, }; @@ -291,12 +289,6 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => { onCreate={handleCreate} /> )} - {editProfileModalVisible && ( - setEditProfileModalVisible(false)} - /> - )} ); }; diff --git a/web-app/src/context/AuthContext.tsx b/web-app/src/context/AuthContext.tsx index 95b6bf3a..1187df83 100644 --- a/web-app/src/context/AuthContext.tsx +++ b/web-app/src/context/AuthContext.tsx @@ -1,21 +1,15 @@ "use client"; -import React, { useCallback, useEffect, useState } from "react"; -import { useRouter } from "next/navigation"; -import { getAccountId } from "@didtools/pkh-ethereum"; -import { Cacao, SiweMessage } from "@didtools/cacao"; +import { appConfig } from "@/config"; import { normalizeAccountId } from "@ceramicnetwork/common"; -// import { useAppDispatch, useAppSelector } from "hooks/store"; +import { Cacao, SiweMessage } from "@didtools/cacao"; +import { getAccountId } from "@didtools/pkh-ethereum"; import { getAddress } from "@ethersproject/address"; import { randomBytes, randomString } from "@stablelib/random"; -import { DIDSession, createDIDKey, createDIDCacao } from "did-session"; -// import { -// disconnectApp, selectConnection, setAuthLoading, -// } from "store/slices/connectionSlice"; +import { DIDSession, createDIDCacao, createDIDKey } from "did-session"; +import { useRouter } from "next/navigation"; +import React, { useCallback, useEffect, useState } from "react"; import { switchTestNetwork } from "utils/helper"; -// import OriginWarningModal from "../modal/OriginWarningModal"; -import { appConfig } from "@/config"; -// import litService from "services/lit-service"; declare global { interface Window { @@ -55,8 +49,7 @@ const defaultAuthContext = { // session: DIDSession, // }; -export const AuthContext = - React.createContext(defaultAuthContext); +export const AuthContext = React.createContext(defaultAuthContext); export const AuthProvider = ({ children }: any) => { const SESSION_KEY = "did"; @@ -74,7 +67,7 @@ export const AuthProvider = ({ children }: any) => { useEffect(() => { // TODO: no force connect - authenticate(); + // authenticate(); // checkSession(); }, [status]); @@ -87,10 +80,10 @@ export const AuthProvider = ({ children }: any) => { }, [session]); const disconnect = () => { - localStorage.removeItem("provider"); localStorage.removeItem(SESSION_KEY); setSession(undefined); // dispatch(disconnectApp()); + // router.push("/"); router.push("/"); }; @@ -207,14 +200,11 @@ export const AuthProvider = ({ children }: any) => { isLoading, }} > - {/* {status === AuthStatus.FAILED - && originNFTModalVisible ? : <>} */} {children} ); }; -//useauth hook export const useAuth = () => { const context = React.useContext(AuthContext); if (!context) { diff --git a/web-app/src/context/CeramicProvider.tsx b/web-app/src/context/CeramicProvider.tsx index 5e6d32fb..543ac0fc 100644 --- a/web-app/src/context/CeramicProvider.tsx +++ b/web-app/src/context/CeramicProvider.tsx @@ -85,7 +85,7 @@ // } // return client.setUserIndex(index_id, type, true); // }; - + // const removeUserIndex = async (index_id: string, type: string) => { // if (!client.isUserAuthenticated()) { // throw new Error("Invalid client"); diff --git a/web-app/src/hooks/store.ts b/web-app/src/hooks/store.ts deleted file mode 100644 index a2f3fd1d..00000000 --- a/web-app/src/hooks/store.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"; -import type { RootState, AppDispatch } from "../store"; - -export const useAppDispatch = () => useDispatch(); -export const useAppSelector: TypedUseSelectorHook = useSelector; diff --git a/web-app/src/hooks/useAtBottom.tsx b/web-app/src/hooks/useAtBottom.tsx index 70c831c9..e377424a 100644 --- a/web-app/src/hooks/useAtBottom.tsx +++ b/web-app/src/hooks/useAtBottom.tsx @@ -6,8 +6,8 @@ export function useAtBottom(offset = 0) { React.useEffect(() => { const handleScroll = () => { setIsAtBottom( - window.innerHeight + window.scrollY >= - document.body.offsetHeight - offset, + window.innerHeight + window.scrollY + >= document.body.offsetHeight - offset, ); }; diff --git a/web-app/src/hooks/useEnterSubmit.tsx b/web-app/src/hooks/useEnterSubmit.tsx index deedaa16..30805d5f 100644 --- a/web-app/src/hooks/useEnterSubmit.tsx +++ b/web-app/src/hooks/useEnterSubmit.tsx @@ -10,9 +10,9 @@ export function useEnterSubmit(): { event: React.KeyboardEvent, ): void => { if ( - event.key === "Enter" && - !event.shiftKey && - !event.nativeEvent.isComposing + event.key === "Enter" + && !event.shiftKey + && !event.nativeEvent.isComposing ) { formRef.current?.requestSubmit(); event.preventDefault(); diff --git a/web-app/src/hooks/useLinks.tsx b/web-app/src/hooks/useLinks.tsx index 47cdad3b..8d749559 100644 --- a/web-app/src/hooks/useLinks.tsx +++ b/web-app/src/hooks/useLinks.tsx @@ -1,6 +1,3 @@ -import React, { useContext } from "react"; -import { IndexLink } from "../types/entity"; - // export interface LinksContextValue { // links: IndexLink[]; // setLinks: (links: IndexLink[]) => void; diff --git a/web-app/src/hooks/useOwner.ts b/web-app/src/hooks/useOwner.ts deleted file mode 100644 index fe641cd4..00000000 --- a/web-app/src/hooks/useOwner.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { useRouter } from "next/router"; -import { useEffect, useState } from "react"; -import { selectConnection } from "store/slices/connectionSlice"; -import { useAppSelector } from "./store"; - -export interface OwnerState { - isOwner: boolean; - did?: string; -} -export const useOwner = () => { - const router = useRouter(); - const { did } = useAppSelector(selectConnection); - - const getState = () => ({ - isOwner: router.query && ((router.query || {}).did as string || "").toLowerCase() === (did || "").toLowerCase(), - did: (router.query || {}).did === did ? did : (router.query || {}).did as string, - }); - - const [state, setState] = useState(() => getState()); - - useEffect(() => { - setState(() => getState()); - }, [router.query.did, did]); - - return state; -}; diff --git a/web-app/src/hooks/useRouteParams.ts b/web-app/src/hooks/useRouteParams.ts index f12a5a02..da68e752 100644 --- a/web-app/src/hooks/useRouteParams.ts +++ b/web-app/src/hooks/useRouteParams.ts @@ -1,6 +1,6 @@ // import { useParams } from 'next/navigation'; -import { useParams } from "next/navigation" +import { useParams } from "next/navigation"; export const useRouteParams = () => { const params = useParams(); @@ -9,7 +9,6 @@ export const useRouteParams = () => { return { id }; }; - // index.network/discovery/:did // export const useRouteParams = () => { // const path = usePathname(); @@ -17,4 +16,3 @@ export const useRouteParams = () => { // return { did }; // } - diff --git a/web-app/src/hooks/useScrollRestoration.tsx b/web-app/src/hooks/useScrollRestoration.tsx index 300d6146..dad3d592 100644 --- a/web-app/src/hooks/useScrollRestoration.tsx +++ b/web-app/src/hooks/useScrollRestoration.tsx @@ -16,8 +16,8 @@ function useScrollRestoration() { function loadScroll() { const isWindowExist = typeof window !== "undefined"; - const record = isWindowExist && - window.sessionStorage ? JSON.parse(window.sessionStorage.getItem("scrollPosition") || "undefined") : null; + const record = isWindowExist + && window.sessionStorage ? JSON.parse(window.sessionStorage.getItem("scrollPosition") || "undefined") : null; if (isWindowExist && router.pathname === record.pathname) { window.scrollTo(0, parseInt(record.position)); } diff --git a/web-app/src/services/api-service-new.ts b/web-app/src/services/api-service-new.ts index d917074b..f4ea446e 100644 --- a/web-app/src/services/api-service-new.ts +++ b/web-app/src/services/api-service-new.ts @@ -5,8 +5,8 @@ import { appConfig } from "config"; import { DIDSession } from "did-session"; import { Indexes, Link, Users } from "types/entity"; import { DEFAULT_CREATE_INDEX_TITLE } from "utils/constants"; -import litService from "./lit-service"; import { CID } from "multiformats"; +import litService from "./lit-service"; const API_ENDPOINTS = { CHAT_STREAM: "/chat_stream", @@ -183,10 +183,9 @@ class ApiService { if (add) { const { data } = await this.apiAxios.put(url); return data; - } else { + } const { data } = await this.apiAxios.delete(url); return data; - } } async ownIndex(did: string, indexId: string, add: boolean) { const url = API_ENDPOINTS.OWN_INDEX.replace(":did", did).replace( @@ -197,10 +196,9 @@ class ApiService { if (add) { const { data } = await this.apiAxios.put(url); return data; - } else { + } const { data } = await this.apiAxios.delete(url); return data; - } } async getItems(indexId: string, queryParams: GetItemQueryParams = {}) { @@ -209,7 +207,7 @@ class ApiService { // cursor: "eyJ0eXBlIjoiY29udGVudCIsImlkIjoia2p6bDZrY3ltN3c4eWE1dGZ4dTk3djEweHNoMWQwNmh6a2h5MGl0ZzQ0ajBrcGxhbWNzMGNjbm51cGE2MGhzIiwidmFsdWUiOnsiY3JlYXRlZEF0IjoiMjAyNC0wMi0wMVQxMjo0NDoyMi40NThaIn19", // }; if (queryParams) { - let formattedQuery = Object.entries(queryParams) + const formattedQuery = Object.entries(queryParams) .map(([key, value]) => `${key}=${value}`) .join("&"); url = `${url}?${new URLSearchParams(formattedQuery)}`; diff --git a/web-app/src/services/lit-service.ts b/web-app/src/services/lit-service.ts index e11f0e88..e777db12 100644 --- a/web-app/src/services/lit-service.ts +++ b/web-app/src/services/lit-service.ts @@ -1,4 +1,4 @@ -import { ContractTransactionResponse, ethers } from "ethers"; +import { ethers } from "ethers"; import { LitContracts } from "@lit-protocol/contracts-sdk"; import { DID } from "dids"; import * as LitJsSdk from "@lit-protocol/lit-node-client"; @@ -20,8 +20,7 @@ class LitService { const mintCost = await litContracts.pkpNftContract.read.mintCost(); const acid = litContracts.utils.getBytesFromMultihash(appConfig.defaultCID); - const mint = - (await litContracts.pkpHelperContract.write.mintNextAndAddAuthMethods( + const mint = (await litContracts.pkpHelperContract.write.mintNextAndAddAuthMethods( 2, [2], [acid], @@ -32,9 +31,10 @@ class LitService { { value: mintCost, }, - )) as ContractTransactionResponse; + )) as any; const wait = await mint.wait(); + /* eslint-disable */ const tokenIdFromEvent = wait?.logs ? wait.logs[0].topics[1] : wait?.logs[0].topics[1]; @@ -109,7 +109,7 @@ class LitService { return false; } - const resp = await litNodeClient.executeJs({ + const resp = (await litNodeClient.executeJs({ ipfsId: collabAction, authSig, jsParams: { @@ -121,7 +121,7 @@ class LitService { domain: window.location.host, sigName: "sig1", }, - }); + })) as any; // @ts-ignore const { error } = resp.response; // TODO Handle. if (error) { diff --git a/web-app/src/store/index.ts b/web-app/src/store/index.ts deleted file mode 100644 index 5e635aca..00000000 --- a/web-app/src/store/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// import { configureStore } from "@reduxjs/toolkit"; -// import connectionReducer from "./slices/connectionSlice"; -// import profileReducer from "./slices/profileSlice"; - -// export const store = configureStore({ -// reducer: { -// connection: connectionReducer, -// profile: profileReducer, -// }, -// }); - -// export type RootState = ReturnType; -// export type AppDispatch = typeof store.dispatch; diff --git a/web-app/src/store/slices/connectionSlice.ts b/web-app/src/store/slices/connectionSlice.ts deleted file mode 100644 index f7598812..00000000 --- a/web-app/src/store/slices/connectionSlice.ts +++ /dev/null @@ -1,74 +0,0 @@ -// import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -// import type { RootState } from ".."; - -// // Define a type for the slice state -// interface ConnectionState { -// metaMaskConnected: boolean; -// connected: boolean; -// originNFTModalVisible: boolean; -// loading: boolean -// did?: string; -// } - -// // Define the initial state using that type -// const initialState: ConnectionState = { -// metaMaskConnected: false, -// connected: false, -// originNFTModalVisible: false, -// loading: true, -// }; - -// export const connectionSlice = createSlice({ -// name: "connection", -// // `createSlice` will infer the state type from the `initialState` argument -// initialState, -// reducers: { -// setAuthLoading: (state, action: PayloadAction) => ({ -// ...state, -// loading: action.payload, -// }), -// setOriginNFTModalVisible: (state, action: PayloadAction) => ({ -// ...state, -// originNFTModalVisible: action.payload, -// }), -// setMetaMaskConnected: (state, action: PayloadAction<{ -// did?: string, -// metaMaskConnected: boolean -// }>) => { -// const { did, metaMaskConnected } = action.payload; - -// return { -// ...state, -// metaMaskConnected, -// did, -// }; -// }, -// // setConnected: (state, action: PayloadAction) => ({ -// // ...state, -// // connected: action.payload, -// // }), - -// disconnectApp: () => initialState, -// resetAuth: (state) => ({ -// ...state, -// metaMaskConnected: false, -// connected: false, -// originNFTModalVisible: false, -// did: undefined, -// }), -// }, -// }); - -// export const { -// setAuthLoading, -// setOriginNFTModalVisible, -// setMetaMaskConnected, -// // setConnected, -// disconnectApp, -// resetAuth, -// } = connectionSlice.actions; - -// // Other code such as selectors can use the imported `RootState` type -// export const selectConnection = (state: RootState) => state.connection; - -// export default connectionSlice.reducer; diff --git a/web-app/src/store/slices/profileSlice.ts b/web-app/src/store/slices/profileSlice.ts deleted file mode 100644 index 516f6f3e..00000000 --- a/web-app/src/store/slices/profileSlice.ts +++ /dev/null @@ -1,28 +0,0 @@ -// import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -// import type { Users } from "types/entity"; -// import type { RootState } from ".."; - -// export type ProfileState = Partial & { -// available: boolean; -// }; - -// const initialState: ProfileState = { -// available: false, -// }; - -// export const profileSlice = createSlice({ -// name: "connection", -// initialState, -// reducers: { -// setProfile(state, action: PayloadAction) { -// return action.payload; -// }, -// resetProfile: () => initialState, -// }, -// }); - -// export const { setProfile, resetProfile } = profileSlice.actions; - -// export const selectProfile = (state: RootState) => state.profile; - -// export default profileSlice.reducer; diff --git a/web-app/src/utils/helper.ts b/web-app/src/utils/helper.ts index 1034740a..40f91db3 100644 --- a/web-app/src/utils/helper.ts +++ b/web-app/src/utils/helper.ts @@ -5,8 +5,7 @@ export function copyToClipboard(str?: string) { if (navigator && navigator.clipboard) navigator.clipboard.writeText(str || ""); else { const temp = document.createElement("input"); - const newStyle: Partial = - { + const newStyle: Partial = { position: "absolute", left: "-5000px", top: "-5000px", @@ -30,9 +29,9 @@ export function generateRandomColor() { export function isSSR() { return !( - typeof window !== "undefined" && - window.document && - window.document.createElement + typeof window !== "undefined" + && window.document + && window.document.createElement ); }