Merge pull request #308 from plebbit/development

Development
This commit is contained in:
plebeius.eth
2023-12-15 12:26:29 +01:00
committed by GitHub
13 changed files with 154 additions and 62 deletions
+2 -2
View File
@@ -9,7 +9,7 @@
"@capacitor/android": "3.6.0",
"@capacitor/app": "1.1.1",
"@capacitor/core": "3.6.0",
"@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#7aca3428098041eaea2a82ee4b041bb552a4ba99",
"@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#4d667f7ad7a77cfd416184acffd6f561761ebc9b",
"@testing-library/dom": "9.0.1",
"@testing-library/jest-dom": "5.14.1",
"@testing-library/react": "14.0.0",
@@ -44,8 +44,8 @@
"rehype-sanitize": "5.0.1",
"remark-breaks": "3.0.2",
"styled-components": "5.3.9",
"web-vitals": "3.3.0",
"tcp-port-used": "1.0.2",
"web-vitals": "3.3.0",
"zustand": "4.3.6"
},
"scripts": {
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

+2 -2
View File
@@ -93,11 +93,11 @@ export default function App() {
// fetch default subplebbits
useEffect(() => {
let didCancel = false;
fetch('https://raw.githubusercontent.com/plebbit/temporary-default-subplebbits/master/subplebbits.json', { cache: 'no-cache' })
fetch('https://raw.githubusercontent.com/plebbit/temporary-default-subplebbits/master/multisub.json', { cache: 'no-cache' })
.then((res) => res.json())
.then((res) => {
if (!didCancel) {
setDefaultSubplebbits(res);
setDefaultSubplebbits(res.subplebbits);
}
});
return () => {
+102 -27
View File
@@ -5,6 +5,7 @@ import {
createAccount,
deleteAccount,
deleteCaches,
exportAccount,
importAccount,
setAccount,
setActiveAccount,
@@ -354,27 +355,6 @@ const SettingsModal = ({ isOpen, closeModal }) => {
}
};
const handleImportAccount = async () => {
const data = importRef.current.value;
try {
const parsedJson = JSON.parse(data);
await importAccount(data);
setActiveAccount(parsedJson.account?.name);
if (parsedJson.account?.author?.address.endsWith('.eth') && anonymousMode === true) {
setAnonymousMode(false);
localStorage.setItem('successToast', 'Account imported successfully. ENS address detected, Anon mode disabled.');
window.location.reload();
} else {
setNewSuccessMessage('Account imported successfully.');
}
} catch (error) {
setNewErrorMessage(error.message);
console.log(error);
}
};
const handleDeleteAccount = async () => {
if (window.confirm('Are you sure you want to delete this account?')) {
try {
@@ -432,6 +412,92 @@ const SettingsModal = ({ isOpen, closeModal }) => {
}
};
const [switchToLastAccount, setSwitchToLastAccount] = useState(false);
useEffect(() => {
if (switchToLastAccount && accounts.length > 0) {
const lastAccount = accounts[accounts.length - 1];
setActiveAccount(lastAccount.name);
setSwitchToLastAccount(false);
}
}, [accounts, switchToLastAccount]);
const _importAccount = async () => {
// Create a file input element
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = '.json';
// Handle file selection
fileInput.onchange = async (event) => {
try {
const files = event.target.files;
if (!files || files.length === 0) {
throw new Error('No file selected.');
}
const file = files[0];
// Read the file content
const reader = new FileReader();
reader.onload = async (e) => {
const fileContent = e.target.result;
if (typeof fileContent !== 'string') {
throw new Error('File content is not a string.');
}
const newAccount = JSON.parse(fileContent);
await importAccount(fileContent);
setSwitchToLastAccount(true);
alert(`Imported ${newAccount.account?.name}`);
};
reader.readAsText(file);
} catch (error) {
if (error instanceof Error) {
alert(error.message);
console.log(error);
} else {
console.error('An unknown error occurred:', error);
}
}
};
// Trigger file selection dialog
fileInput.click();
};
const _exportAccount = async () => {
try {
const accountString = await exportAccount();
const accountObject = JSON.parse(accountString);
const formattedAccountJson = JSON.stringify(accountObject, null, 2);
// Create a Blob from the JSON string
const blob = new Blob([formattedAccountJson], { type: 'application/json' });
// Create a URL for the Blob
const fileUrl = URL.createObjectURL(blob);
// Create a temporary download link
const link = document.createElement('a');
link.href = fileUrl;
link.download = `${account.name}.json`;
// Append the link, trigger the download, then remove the link
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// Release the Blob URL
URL.revokeObjectURL(fileUrl);
} catch (error) {
if (error instanceof Error) {
alert(error.message);
console.log(error);
} else {
console.error('An unknown error occurred:', error);
}
}
};
return (
<StyledModal
isOpen={isOpen}
@@ -489,9 +555,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
</li>
<li className='settings-tip anon-tip'>Use a newly generated u/address per thread to post.</li>
<li className='settings-option disc'>Account Data</li>
<li className='settings-tip'>
Save manual changes, reset changes, import another account after pasting its whole data, delete the account, create a new account.
</li>
<li className='settings-tip'>Manually edit your account data using the preview below.</li>
<div className='settings-input'>
<textarea
id='account-data-text'
@@ -505,11 +569,22 @@ const SettingsModal = ({ isOpen, closeModal }) => {
<div className='account-buttons'>
<button onClick={handleSaveAccount}>Save</button>
<button onClick={() => setEditedAccountJson(accountJson)}>Reset</button>
<button onClick={handleImportAccount}>Import</button>
<button onClick={handleDeleteAccount}>Delete</button>
<button onClick={handleCreateAccount}>Create</button>
</div>
</div>
<div className='account-options'>
<li className='settings-tip'>
<button onClick={_exportAccount}>Export</button> your full account data
</li>
<li className='settings-tip'>
<button onClick={_importAccount}>Import</button> full account data
</li>
<li className='settings-tip'>
<button onClick={handleCreateAccount}>Create</button> a new account
</li>
<li className='settings-tip'>
<button onClick={handleDeleteAccount}>Delete</button> this account
</li>
</div>
<li className='settings-option disc'>Account Address: u/{account?.author.shortAddress}</li>
<li className='settings-tip'>Select a different account to use in the dropdown below.</li>
<li>
@@ -44,6 +44,7 @@ export const GlobalStyle = createGlobalStyle`
.poster-address {
display: inline-block;
overflow-x: clip;
}
.author-address-hidden {
@@ -2,6 +2,12 @@ import styled from 'styled-components';
import Modal from 'react-modal';
export const StyledModal = styled(Modal)`
.account-options {
padding-top: 5px;
padding-left: 25px;
margin-bottom: -10px;
}
.panel {
top: 60px;
width: 400px;
+5 -6
View File
@@ -1125,12 +1125,11 @@ const All = () => {
Plebbit
</a>
</li>
{/* <li onClick={() => handleOptionClick(thread.cid)}>
<a
href={`https://seedit.eth.limo/#/p/${thread.subplebbitAddress}/c/${thread.cid}`}
target="_blank" rel="noreferrer"
>Seedit</a>
</li> */}
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://seedit.netlify.app/#/p/${thread.subplebbitAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Seedit
</a>
</li>
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://plebones.eth.limo/#/p/${thread.subplebbitAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Plebones
+1 -1
View File
@@ -653,7 +653,7 @@ const CatalogPost = ({ post }) => {
</li>
{/* <li onClick={() => handleOptionClick(thread.cid)}>
<a
href={`https://seedit.eth.limo/#/p/${selectedAddress}/c/${thread.cid}`}
href={`https://seedit.netlify.app/#/p/${selectedAddress}/c/${thread.cid}`}
target="_blank" rel="noreferrer"
>Seedit</a>
</li> */}
+5 -6
View File
@@ -2181,12 +2181,11 @@ const Board = () => {
Plebbit
</a>
</li>
{/* <li onClick={() => handleOptionClick(thread.cid)}>
<a
href={`https://seedit.eth.limo/#/p/${selectedAddress}/c/${thread.cid}`}
target="_blank" rel="noreferrer"
>Seedit</a>
</li> */}
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://seedit.netlify.app/#/p/${selectedAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Seedit
</a>
</li>
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://plebones.eth.limo/#/p/${selectedAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Plebones
+5 -6
View File
@@ -1075,12 +1075,11 @@ const CatalogPost = ({ post }) => {
Plebbit
</a>
</li>
{/* <li onClick={() => handleOptionClick(thread.cid)}>
<a
href={`https://seedit.eth.limo/#/p/${selectedAddress}/c/${thread.cid}`}
target="_blank" rel="noreferrer"
>Seedit</a>
</li> */}
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://seedit.netlify.app/#/p/${selectedAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Seedit
</a>
</li>
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://plebones.eth.limo/#/p/${selectedAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Plebones
+5 -6
View File
@@ -1139,12 +1139,11 @@ const Subscriptions = () => {
Plebbit
</a>
</li>
{/* <li onClick={() => handleOptionClick(thread.cid)}>
<a
href={`https://seedit.eth.limo/#/p/${thread.subplebbitAddress}/c/${thread.cid}`}
target="_blank" rel="noreferrer"
>Seedit</a>
</li> */}
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://seedit.netlify.app/#/p/${thread.subplebbitAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Seedit
</a>
</li>
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://plebones.eth.limo/#/p/${thread.subplebbitAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Plebones
@@ -651,12 +651,11 @@ const CatalogPost = ({ post }) => {
Plebbit
</a>
</li>
{/* <li onClick={() => handleOptionClick(thread.cid)}>
<a
href={`https://seedit.eth.limo/#/p/${selectedAddress}/c/${thread.cid}`}
target="_blank" rel="noreferrer"
>Seedit</a>
</li> */}
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://seedit.netlify.app/#/p/${selectedAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Seedit
</a>
</li>
<li onClick={() => handleOptionClick(thread.cid)}>
<a href={`https://plebones.eth.limo/#/p/${selectedAddress}/c/${thread.cid}`} target='_blank' rel='noreferrer'>
Plebones
+15
View File
@@ -2867,6 +2867,21 @@
dependencies:
debug "4.3.3"
"@plebbit/plebbit-react-hooks@https://github.com/plebbit/plebbit-react-hooks.git#4d667f7ad7a77cfd416184acffd6f561761ebc9b":
version "0.0.1"
resolved "https://github.com/plebbit/plebbit-react-hooks.git#4d667f7ad7a77cfd416184acffd6f561761ebc9b"
dependencies:
"@plebbit/plebbit-js" "https://github.com/plebbit/plebbit-js.git#70f898084d7ffb4dd6187fcb00bb36b6fa3e9d25"
"@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"
"@plebbit/plebbit-react-hooks@https://github.com/plebbit/plebbit-react-hooks.git#7aca3428098041eaea2a82ee4b041bb552a4ba99":
version "0.0.1"
resolved "https://github.com/plebbit/plebbit-react-hooks.git#7aca3428098041eaea2a82ee4b041bb552a4ba99"