From 1f0bf371094010f751f903937a600931ef7ea205 Mon Sep 17 00:00:00 2001
From: Renard
Date: Mon, 30 Sep 2019 22:11:19 -0300
Subject: Añadidos: Settings ✨
---
src/App.css | 9 +++
src/App.js | 57 +++++++++++--------
src/Home.js | 12 +++-
src/Post.js | 15 +++--
src/ReplyForm.js | 3 +-
src/Settings.js | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/Thread.js | 11 +++-
7 files changed, 242 insertions(+), 34 deletions(-)
create mode 100644 src/Settings.js
diff --git a/src/App.css b/src/App.css
index 73001f9..7bf667b 100644
--- a/src/App.css
+++ b/src/App.css
@@ -182,4 +182,13 @@
.ui.items>.item>.content>a.header.inverted {
color: #4183C4;
;
+}
+
+.ui.checkbox,
+.select {
+ margin-top: 0.5em;
+}
+
+.settingCheckbox {
+ display: block !important;
}
\ No newline at end of file
diff --git a/src/App.js b/src/App.js
index 94b3156..c3631e2 100644
--- a/src/App.js
+++ b/src/App.js
@@ -20,6 +20,7 @@ import NotFound from "./NotFound";
import ThreadList from "./ThreadList";
import FAQ from "./FAQ";
import ChangeLogPage from "./ChangelogPage";
+import SettingsModal from "./Settings";
class App extends Component {
constructor() {
@@ -29,7 +30,7 @@ class App extends Component {
isLoaded: false,
nightMode: false
};
- this.toggleTheme = this.toggleTheme.bind(this);
+ this.updateTheme = this.updateTheme.bind(this);
}
componentDidMount() {
@@ -56,18 +57,31 @@ class App extends Component {
});
});
- let _nightMode = localStorage.getItem("nightMode");
- if (_nightMode === null) {
- localStorage.setItem("nightMode", false);
+ let lsSettings = localStorage.getItem("settings");
+ let settings = JSON.parse(lsSettings);
+
+ if (lsSettings === null) {
+ let defaultSettings = {
+ homeSound: "msn",
+ threadSound: "msn",
+ nightMode: false,
+ notifyOnHome: true,
+ notifyOnThread: true,
+ autoUpdateThreads: true,
+ showAvatars: true,
+ postPassword: this.genPassword()
+ };
+ localStorage.setItem("settings", JSON.stringify(defaultSettings));
+ settings = defaultSettings;
} else {
- this.setState({ nightMode: JSON.parse(_nightMode) });
- }
- let password = localStorage.getItem("password");
- if (password === null) {
- localStorage.setItem("password", this.genPassword());
+ this.setState({ nightMode: settings.nightMode });
}
}
+ updateTheme(mode) {
+ this.setState({ nightMode: mode });
+ }
+
genPassword() {
let pass = "";
for (let i = 0; i < 10; i++) {
@@ -95,12 +109,6 @@ class App extends Component {
}
}
- toggleTheme() {
- this.setState({ nightMode: !this.state.nightMode }, () => {
- localStorage.setItem("nightMode", this.state.nightMode);
- });
- }
-
render() {
const { boardList, nightMode, isLoaded } = this.state;
@@ -120,8 +128,9 @@ class App extends Component {
Home
-
+
+ Bolletin Board System
{boardList.map(board =>
board.board_type === 1 ? (
) : null
)}
-
-
-
-
+ Imageboard
{boardList.map(board =>
board.board_type === 0 ? (
FAQ
-
- {nightMode ? : }
-
+
+
+
+ }
+ handler={this.updateTheme}
+ />
diff --git a/src/Home.js b/src/Home.js
index 0cdad72..1695ed4 100644
--- a/src/Home.js
+++ b/src/Home.js
@@ -19,8 +19,9 @@ class Home extends Component {
this.refreshCooldown = 15;
this.cooldownCounter = 0;
this.lastTimeNoAge = 0;
+ let homeSound = JSON.parse(localStorage.getItem("settings")).homeSound;
this.notificationSound = new Audio(
- "https://bienvenidoainternet.org/msn.ogg"
+ `https://bienvenidoainternet.org/static/sfx/${homeSound}.ogg`
);
this.handeMouseMove = this.handeMouseMove.bind(this);
this.mouseVars = {};
@@ -77,6 +78,9 @@ class Home extends Component {
}
async updateAges() {
+ if (!JSON.parse(localStorage.getItem("settings")).autoUpdateThreads) {
+ return;
+ }
this.cooldownCounter++;
if (this.cooldownCounter < this.refreshCooldown) {
return;
@@ -96,7 +100,9 @@ class Home extends Component {
lastAgeThreads: resource.threads
});
this.refreshCooldown = 30;
- this.notificationSound.play();
+ if (JSON.parse(localStorage.getItem("settings")).notifyOnHome) {
+ this.notificationSound.play();
+ }
} else {
this.refreshCooldown += 15;
this.lastTimeNoAge = resource.time;
@@ -131,7 +137,7 @@ class Home extends Component {
className={nightMode ? "homeContainer inverted" : "homeContainer"}
>
-
+
BaI
diff --git a/src/Post.js b/src/Post.js
index 18d81e0..68ba36e 100644
--- a/src/Post.js
+++ b/src/Post.js
@@ -91,7 +91,7 @@ class Post extends Component {
handleConfirm() {
this.setState({ deleteDialog: false });
const { post, currentBoard } = this.props;
- let password = localStorage.getItem("password");
+ let password = JSON.parse(localStorage.getItem("settings")).postPassword;
fetch(
`https://bienvenidoainternet.org/cgi/api/delete?dir=${currentBoard.dir}&id=${post.id}&password=${password}`
)
@@ -251,12 +251,17 @@ class Post extends Component {
isDeleteable = false;
}
+ let settingRenderAvatar = JSON.parse(localStorage.getItem("settings"))
+ .showAvatars;
+
return (
-
+ {settingRenderAvatar && (
+
+ )}
{
+ new Audio(
+ `https://bienvenidoainternet.org/static/sfx/${
+ name === "threadSound" ? this.state.threadSound : this.state.homeSound
+ }.ogg`
+ ).play();
+ this.saveSettings();
+ });
+ }
+
+ toggleSetting(e, { name, checked }) {
+ this.setState({ [name]: checked }, () => {
+ this.props.handler(this.state.nightMode);
+ this.saveSettings();
+ });
+ }
+
+ saveSettings() {
+ localStorage.setItem("settings", JSON.stringify(this.state));
+ }
+
+ render() {
+ const {
+ homeSound,
+ threadSound,
+ nightMode,
+ autoUpdateThreads,
+ notifyOnHome,
+ notifyOnThread,
+ postPassword,
+ showAvatars
+ } = this.state;
+ return (
+
+ Configuración
+
+
+
+
+
+
+
+
+
+ Sonido de notificación:{" "}
+
+
+
+
+
+ Sonido de notificación :{" "}
+
+
+
+
+
+
+
+ );
+ }
+}
+
+export default SettingsModal;
diff --git a/src/Thread.js b/src/Thread.js
index c79e7e0..b656b9f 100644
--- a/src/Thread.js
+++ b/src/Thread.js
@@ -28,8 +28,9 @@ class Thread extends Component {
this.refreshCooldown = 15;
this.cooldownCounter = 0;
this.newPostCounter = 0;
+ let threadSound = JSON.parse(localStorage.getItem("settings")).threadSound;
this.notificationSound = new Audio(
- "https://bienvenidoainternet.org/msn.ogg"
+ `https://bienvenidoainternet.org/static/sfx/${threadSound}.ogg`
);
}
@@ -64,6 +65,10 @@ class Thread extends Component {
}
async updateReplies() {
+ if (!JSON.parse(localStorage.getItem("settings")).autoUpdateThreads) {
+ return;
+ }
+
this.cooldownCounter++;
if (this.cooldownCounter < this.refreshCooldown) {
return;
@@ -87,7 +92,9 @@ class Thread extends Component {
const newPosts = this.state.thread.posts.concat(resource.posts);
this.refreshCooldown = 15;
this.newPostCounter += resource.posts.length;
- this.notificationSound.play();
+ if (JSON.parse(localStorage.getItem("settings")).notifyOnThread) {
+ this.notificationSound.play();
+ }
this.setState(({ thread }) => ({
thread: {
...thread,
--
cgit v1.2.1-18-gbd029