getting theme from backend

This commit is contained in:
2020-10-09 23:41:16 +03:00
parent 9591d3f9fe
commit a6ae3fd69f
3 changed files with 1325 additions and 1243 deletions
+1309 -1236
View File
File diff suppressed because it is too large Load Diff
+7 -6
View File
@@ -6,7 +6,7 @@ import Novel from "../Novel/Novel";
import User from "../User/User";
import Main from "../Main/Main"
import NotFoundError from "../NotFoundError";
import {fetchCurrentUser} from "../../api/users";
import {fetchCurrentUser, fetchUserSettings} from "../../api/users";
import {connect} from "react-redux";
import {setUser} from "../../store/actions";
import Character from "../Character/Character";
@@ -42,14 +42,15 @@ class App extends React.Component<Props, State> {
super(props);
const { setUser } = this.props;
fetchCurrentUser().then(setUser).catch((err: ApiError) => {
fetchCurrentUser().then((user: UserType) => {
setUser(user);
fetchUserSettings().then((settings: UserSettingsType) => {
document.body.setAttribute('theme', settings.theme);
});
}).catch((err: ApiError) => {
if(err.code !== 3 && err.text) console.error(err.text);
});
const theme = localStorage.getItem('theme');
if(theme)
document.body.setAttribute('theme', theme);
parser.registerTag('spoiler', SpoilerTag);
parser.registerTag('color', ColorTag);
+9 -1
View File
@@ -1,3 +1,5 @@
type Theme = 'dark' | 'blue' | 'red' | 'green' | 'light'
type ApiError = {
code: number
text: string
@@ -41,6 +43,12 @@ type UserType = {
is_activated: boolean
}
type UserSettingsType = {
avatar: string
theme: Theme
use_gravatar: boolean
}
type UserNovelType = {
mark?: number
status: string
@@ -83,4 +91,4 @@ type StoreState = {
modal: React.ReactNode
}
type SetModalType = (modal: React.ReactNode | null) => void
type SetModalType = (modal: React.ReactNode | null) => void