mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
add anonymous mode UI
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import React, { useState, useEffect, useRef } from "react";
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
import { Link, useLocation, useNavigate } from "react-router-dom";
|
import { Link, useLocation, useNavigate } from "react-router-dom";
|
||||||
|
import { confirmAlert } from "react-confirm-alert";
|
||||||
import Modal from "react-modal";
|
import Modal from "react-modal";
|
||||||
import { deleteCaches, exportAccount, importAccount, setAccount, setActiveAccount, useAccount, useAccounts } from "@plebbit/plebbit-react-hooks";
|
import { deleteCaches, exportAccount, importAccount, setAccount, setActiveAccount, useAccount, useAccounts } from "@plebbit/plebbit-react-hooks";
|
||||||
import { StyledModal } from "../styled/modals/SettingsModal.styled";
|
import { StyledModal } from "../styled/modals/SettingsModal.styled";
|
||||||
|
import { AuthorDeleteAlert } from '../styled/views/Thread.styled';
|
||||||
import useGeneralStore from "../../hooks/stores/useGeneralStore";
|
import useGeneralStore from "../../hooks/stores/useGeneralStore";
|
||||||
import useError from "../../hooks/useError";
|
import useError from "../../hooks/useError";
|
||||||
import useSuccess from "../../hooks/useSuccess";
|
import useSuccess from "../../hooks/useSuccess";
|
||||||
@@ -12,6 +14,7 @@ const {version} = packageJson
|
|||||||
|
|
||||||
const SettingsModal = ({ isOpen, closeModal }) => {
|
const SettingsModal = ({ isOpen, closeModal }) => {
|
||||||
const {
|
const {
|
||||||
|
anonymousMode, setAnonymousMode,
|
||||||
selectedStyle,
|
selectedStyle,
|
||||||
} = useGeneralStore(state => state);
|
} = useGeneralStore(state => state);
|
||||||
|
|
||||||
@@ -190,6 +193,38 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
setErrorMessage(error.message);
|
setErrorMessage(error.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const handleAnonymousMode = () => {
|
||||||
|
confirmAlert({
|
||||||
|
customUI: ({ onClose }) => {
|
||||||
|
return (
|
||||||
|
<AuthorDeleteAlert selectedStyle={selectedStyle}>
|
||||||
|
<div className='author-delete-alert'>
|
||||||
|
<p>
|
||||||
|
{ !anonymousMode ?
|
||||||
|
"Enabling anonymous mode will turn off all account-based features, such as subscribing to boards." :
|
||||||
|
"Disabling anonymous mode will turn on all account-based features, such as subscribing to boards."
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
<div className="author-delete-buttons">
|
||||||
|
<button onClick={onClose}>Cancel</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setAnonymousMode(!anonymousMode);
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{ !anonymousMode ? "Enable" : "Disable" }
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AuthorDeleteAlert>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -304,7 +339,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li className="settings-cat-lbl">
|
<li className="settings-cat-lbl">
|
||||||
<span className={`${expanded.includes(2) ? 'minus' : 'plus'}`}
|
<span className={`${expanded.includes(2) ? 'minus' : 'plus'}`}
|
||||||
@@ -379,19 +414,34 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
</ul>
|
</ul>
|
||||||
</ul> */}
|
</ul> */}
|
||||||
</ul>
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li className="anon-off">
|
||||||
|
<label title={ !anonymousMode ?
|
||||||
|
"Enable anonymous mode (turns off all account-based features)" :
|
||||||
|
"Disable anonymous mode (turns on all account-based features)"
|
||||||
|
}>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={!anonymousMode}
|
||||||
|
onChange={handleAnonymousMode}
|
||||||
|
/>
|
||||||
|
Disable anonymous mode
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
className="cache-button"
|
className="cache-button"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (window.confirm("Are you sure you want to clear the cache?")) {
|
if (window.confirm("Are you sure you want to clear the cache?")) {
|
||||||
await deleteCaches();
|
await deleteCaches();
|
||||||
localStorage.setItem("cacheCleared", "true");
|
localStorage.setItem("cacheCleared", "true");
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Clear Cache
|
Clear Cache
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</StyledModal>
|
</StyledModal>
|
||||||
|
|||||||
@@ -190,6 +190,11 @@ export const StyledModal = styled(Modal)`
|
|||||||
left: 23px;
|
left: 23px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.anon-off {
|
||||||
|
padding-left: 3px;
|
||||||
|
padding-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
${({ selectedStyle }) => {
|
${({ selectedStyle }) => {
|
||||||
switch (selectedStyle) {
|
switch (selectedStyle) {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
|
||||||
const useGeneralStore = create((set) => ({
|
const useGeneralStore = create((set) => ({
|
||||||
|
anonymousMode: true,
|
||||||
|
setAnonymousMode: (mode) => set({ anonymousMode: mode }),
|
||||||
|
|
||||||
bodyStyle: JSON.parse(localStorage.getItem('bodyStyle')) || {
|
bodyStyle: JSON.parse(localStorage.getItem('bodyStyle')) || {
|
||||||
background: '#ffe url(assets/fade.png) top repeat-x',
|
background: '#ffe url(assets/fade.png) top repeat-x',
|
||||||
color: 'maroon',
|
color: 'maroon',
|
||||||
|
|||||||
Reference in New Issue
Block a user