From 66e90138d0c2335ffa089a51c23cf60f34f982c0 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 9 May 2023 12:59:00 +0200 Subject: [PATCH] update SettingsModal, add useStateString, fixes --- package.json | 2 +- public/assets/offline.png | Bin 1122 -> 1121 bytes src/components/SettingsModal.jsx | 18 ++++++---- src/hooks/useStateString.js | 47 +++++++++++++++++++++++++ yarn.lock | 57 +++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 src/hooks/useStateString.js 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 dd343f6aefe6965cd494106d530fca2b3f4e9e5a..2ca2cc936bf999d0a150b26d19975df1c76762ff 100644 GIT binary patch delta 411 zcmV;M0c8H-2;m5j7YY;z1^@s6iG0m4ks*%>6aWAK0CYS~B(b?v0Rb?R4g%wUL7>Z= z00040NklAyG z$%kXV_iP+;O{lL}Plu+Ie>q7&jBMMs0BhSe#QU8LzQhH`&rHfz{6uD1mN!9+;~4gR zCqaqf**qRpY?>ww55w@qn|BR=CMVAGOa|W=FfnzT8Rsbnzw0{BM=r!v*^5zve=<=N z0mlLahq!2A6auni5gz3*U%N00UPTTL4@nQ8u5d`D#W}(`4C#46V4?{2eNUWH#}0R< zr8OZcUCS95wmd!D*+DAIKwbNW9nqgV+hAWa?k#cGm*b;o)Z4J-BjQD8a#2TuVe7`^FsKN_XB~rt@c&R^N|1m002ovPDHLk FV1n@fvl{>a delta 412 zcmV;N0b~B*2;vBk7YY^#1^@s6#I$TXks*%>761SM01o^eM6tP40Rb|T4g%wUgf{fG z00041Nklq)j-j8$$S?3MjI2m3{8+m&RO*`M`E27vAw|9A zBDpyBd(Xxptz3Eea@tjU`L9d@Vr0v*I9OfR&Y#a@@FgxdenwKZ;tiQ;n!W|m_q|)! zl>{Y*XZ3tiv0)fA+;!cZH$NJG42~bikqo{uV0`E{GR{*De$zB5A35hk$Vs0BLq~EeRIH2Bh@i!&o(OB@B z;kMcF_<5e~$P8t3OBJ=-4W9K%8d<`hf=8?Ajo@nWX@1xO&G-?nGR(}oD0ie|2u328 z-z#0@=KhZ(kxw^=gs-QQ>RVrf8K?L<2A_UCxo~-tLI&&WY0000 {
  • - + */}
    • { /> toggleExpanded(1)} - >Profile + >Account +
      + + +
      -
    */} +
    • { onClick={() => toggleExpanded(2)} >Plebbit Options
      - -
      + +
      • diff --git a/src/hooks/useStateString.js b/src/hooks/useStateString.js new file mode 100644 index 00000000..b7f21e15 --- /dev/null +++ b/src/hooks/useStateString.js @@ -0,0 +1,47 @@ +import { useMemo } from 'react' + +const useStateString = (clients) => { + const stateString = useMemo(() => { + if (!clients) { + return + } + const states = {} + for (const clientType in clients) { + for (const clientUrl in clients[clientType]) { + const state = clients[clientType][clientUrl].state + if (state === 'stopped') { + continue + } + if (!states[state]) { + states[state] = [] + } + states[state].push(clientUrl) + } + } + + let stateString = '' + for (const state in states) { + const clientUrls = states[state] + const clientHosts = clientUrls.map(clientUrl => new URL(clientUrl).hostname) + + // separate 2 different states using ', ' + if (stateString) { + stateString += ', ' + } + + // e.g. 'fetching IPFS from cloudflare-ipfs.com, ipfs.io' + const formattedState = state.replaceAll('-', ' ').replace('ipfs', 'IPFS').replace('ipns', 'IPNS') + stateString += `${formattedState} from ${clientHosts.join(', ')}` + } + + // capitalize first letter + stateString = stateString.charAt(0).toUpperCase() + stateString.slice(1) + + // if string is empty, return undefined instead + return stateString || undefined + }, [clients]) + + return stateString +} + +export default useStateString \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 3594950f..a1553cf4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2655,6 +2655,48 @@ ts-custom-error "3.3.1" uuid "9.0.0" +"@plebbit/plebbit-js@https://github.com/plebbit/plebbit-js.git#bcf4ec7ba024fdd7dc0bb2fab76c27c93597dd50": + version "0.0.3" + resolved "https://github.com/plebbit/plebbit-js.git#bcf4ec7ba024fdd7dc0bb2fab76c27c93597dd50" + dependencies: + "@keyv/sqlite" "3.6.2" + "@plebbit/plebbit-logger" "github:plebbit/plebbit-logger" + "@types/node-fetch" "2.6.2" + "@types/proper-lockfile" "4.1.2" + "@types/uuid" "8.3.4" + assert "2.0.0" + async-wait-until "2.0.12" + buffer "6.0.3" + captcha-canvas "3.2.1" + err-code "3.0.1" + ethers "5.7.2" + file-type "16.5.4" + form-data "4.0.0" + hpagent "1.2.0" + ipfs-http-client "56.0.3" + ipfs-only-hash "4.0.0" + is-ipfs "6.0.2" + jose "4.11.0" + js-sha256 "0.9.0" + keyv "4.5.2" + knex "2.3.0" + libp2p-crypto "0.21.2" + limiter "2.1.0" + localforage "1.10.0" + lodash-es "4.17.21" + open-graph-scraper "5.2.3" + p-limit "3.1.0" + peer-id "0.16.0" + proper-lockfile "github:plebbit/node-proper-lockfile" + retry "0.13.1" + safe-stable-stringify "2.4.1" + skia-canvas "1.0.0" + sqlite3 "5.1.2" + tiny-typed-emitter "2.1.0" + tinycache "1.1.2" + ts-custom-error "3.3.1" + uuid "9.0.0" + "@plebbit/plebbit-logger@github:plebbit/plebbit-logger": version "0.0.1" uid "9525ca9539479918931c3b334e8d490d1c87e507" @@ -2683,6 +2725,21 @@ uuid "8.3.2" zustand "4.0.0" +"@plebbit/plebbit-react-hooks@https://github.com/plebbit/plebbit-react-hooks.git#e602eda8080f2b3449388c2d5868d6e6da60c8f6": + version "0.0.1" + resolved "https://github.com/plebbit/plebbit-react-hooks.git#e602eda8080f2b3449388c2d5868d6e6da60c8f6" + dependencies: + "@plebbit/plebbit-js" "https://github.com/plebbit/plebbit-js.git#bcf4ec7ba024fdd7dc0bb2fab76c27c93597dd50" + "@plebbit/plebbit-logger" "https://github.com/plebbit/plebbit-logger.git" + assert "2.0.0" + ethers "5.6.9" + localforage "1.10.0" + lodash.isequal "4.5.0" + memoizee "0.4.15" + quick-lru "5.1.1" + uuid "8.3.2" + zustand "4.0.0" + "@pmmmwh/react-refresh-webpack-plugin@^0.5.3": version "0.5.10" resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.10.tgz#2eba163b8e7dbabb4ce3609ab5e32ab63dda3ef8"