diff --git a/package.json b/package.json index 17801e37..d7f8d777 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@babel/plugin-transform-react-jsx": "7.21.0", "@capacitor/android": "3.6.0", "@capacitor/core": "3.6.0", - "@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#91ea5a494fde74836b085e912f671cc5489ecf09", + "@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#e602eda8080f2b3449388c2d5868d6e6da60c8f6", "@testing-library/dom": "9.0.1", "@testing-library/jest-dom": "5.14.1", "@testing-library/react": "14.0.0", diff --git a/public/assets/offline.png b/public/assets/offline.png index a40aa2bb..2ca2cc93 100644 Binary files a/public/assets/offline.png and b/public/assets/offline.png differ diff --git a/src/components/BoardAvatar.jsx b/src/components/BoardAvatar.jsx index 7cbe0f47..8d5a040b 100644 --- a/src/components/BoardAvatar.jsx +++ b/src/components/BoardAvatar.jsx @@ -25,7 +25,7 @@ const BoardAvatar = ({ address }) => { {!isOnline && ( offline )} diff --git a/src/components/OfflineIndicator.jsx b/src/components/OfflineIndicator.jsx index bae408c8..6596c4bf 100644 --- a/src/components/OfflineIndicator.jsx +++ b/src/components/OfflineIndicator.jsx @@ -16,7 +16,7 @@ const OfflineIndicator = ({ address, className, tooltipPlace }) => { alt="offline" src="assets/offline.png" data-tooltip-id="tooltip" - data-tooltip-content="OFFLINE" + data-tooltip-content="Offline" data-tooltip-place={tooltipPlace} /> diff --git a/src/components/ReplyModal.jsx b/src/components/ReplyModal.jsx index f11df31f..fa421a25 100644 --- a/src/components/ReplyModal.jsx +++ b/src/components/ReplyModal.jsx @@ -1,5 +1,4 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'; -import { useLocation } from 'react-router-dom'; import { usePublishComment } from '@plebbit/plebbit-react-hooks'; import { StyledModal } from './styled/ReplyModal.styled'; import useGeneralStore from '../hooks/stores/useGeneralStore'; @@ -33,8 +32,7 @@ const ReplyModal = ({ isOpen, closeModal }) => { const [selectedText, setSelectedText] = useState(''); useError(errorMessage, [errorMessage]); - - const location = useLocation(); + const onModalOpen = () => { @@ -109,7 +107,7 @@ const ReplyModal = ({ isOpen, closeModal }) => { if (index !== undefined) { setPendingCommentIndex(index); } - }, [index, location, setPendingCommentIndex]); + }, [index, setPendingCommentIndex]); const resetFields = useCallback(() => { diff --git a/src/components/SettingsModal.jsx b/src/components/SettingsModal.jsx index d85fa026..766d18c5 100644 --- a/src/components/SettingsModal.jsx +++ b/src/components/SettingsModal.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect, useRef } from "react"; import { Link, useLocation, useNavigate } from "react-router-dom"; import Modal from "react-modal"; -import { deleteCaches, setAccount, useAccount } from "@plebbit/plebbit-react-hooks"; +import { deleteCaches, exportAccount, importAccount, setAccount, setActiveAccount, useAccount, useAccounts } from "@plebbit/plebbit-react-hooks"; import { StyledModal } from "./styled/SettingsModal.styled"; import useGeneralStore from "../hooks/stores/useGeneralStore"; import useError from "../hooks/useError"; @@ -10,28 +10,27 @@ import packageJson from '../../package.json' const {version} = packageJson -const customOverlayStyles = { - overlay: { - backgroundColor: 'rgba(0,0,0,.25)' - } -}; - const SettingsModal = ({ isOpen, closeModal }) => { const selectedStyle = useGeneralStore(state => state.selectedStyle); const navigate = useNavigate(); const location = useLocation(); const [expanded, setExpanded] = useState([]); + const [accountJson, setAccountJson] = useState(null); + const [setImportSuccess] = useState(false); + const [errorMessage, setErrorMessage] = useState(null); const [successMessage, setSuccessMessage] = useState(null); useError(errorMessage, [errorMessage]); useSuccess(successMessage, [successMessage]); const account = useAccount(); + const { accounts } = useAccounts(); const gatewayRef = useRef(); const ipfsRef = useRef(); const pubsubRef = useRef(); const dataPathRef = useRef(); + const importRef = useRef(); const isValidURL = (url) => { try { @@ -108,6 +107,8 @@ const SettingsModal = ({ isOpen, closeModal }) => { const handleCloseModal = () => { + setAccountJson(null); + if (location.pathname.endsWith("/settings")) { const newPath = location.pathname.slice(0, -9); closeModal(); @@ -146,7 +147,31 @@ const SettingsModal = ({ isOpen, closeModal }) => { localStorage.removeItem("cacheCleared"); } }, []); - + + + const handleExport = async () => { + const activeAccountJson = await exportAccount(); + setAccountJson(activeAccountJson); + }; + + + const handleImport = async () => { + const accountJson = importRef.current.value; + + try { + await importAccount(accountJson); + setImportSuccess(true); + localStorage.setItem("toastMessage", "Account Imported"); + window.location.reload(); + + } catch (error) { + setErrorMessage(error.message); + } + }; + + const handleAccountChange = (e) => { + setActiveAccount(e.target.value); + }; return ( @@ -154,7 +179,7 @@ const SettingsModal = ({ isOpen, closeModal }) => { isOpen={isOpen} onRequestClose={handleCloseModal} contentLabel="Settings" - style={customOverlayStyles} + style={{ overlay: { backgroundColor: "rgba(0,0,0,.25)" }}} selectedStyle={selectedStyle} expanded={expanded} > @@ -189,7 +214,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
  • - + */}