Adding a browser default theme option. Fixes #35

This commit is contained in:
Dessalines 2020-09-24 17:03:03 -05:00
parent d68ac84b78
commit 4ef7b10116
3 changed files with 10 additions and 3 deletions

View file

@ -107,7 +107,7 @@ server.get('/*', async (req, res) => {
</noscript>
<div id='root'>${root}</div>
<script src='/static/js/client.js'></script>
<script defer src='/static/js/client.js'></script>
</body>
</html>
`);

View file

@ -535,6 +535,7 @@ export class User extends Component<any, UserState> {
class="ml-2 custom-select w-auto"
>
<option disabled>{i18n.t('theme')}</option>
<option value="browser">{i18n.t('browser_default')}</option>
{themes.map(theme => (
<option value={theme}>{theme}</option>
))}
@ -1050,7 +1051,7 @@ export class User extends Component<any, UserState> {
UserService.Instance.user.show_nsfw;
this.state.userSettingsForm.theme = UserService.Instance.user.theme
? UserService.Instance.user.theme
: 'darkly';
: 'browser';
this.state.userSettingsForm.default_sort_type =
UserService.Instance.user.default_sort_type;
this.state.userSettingsForm.default_listing_type =

View file

@ -437,7 +437,12 @@ export function getMomentLanguage(): string {
}
export function setTheme(theme: string, forceReload: boolean = false) {
if (isBrowser() && (theme !== 'darkly' || forceReload)) {
if (isBrowser() && (theme !== 'browser' || forceReload)) {
// This is only run on a force reload
if (theme == 'browser') {
theme = 'darkly';
}
// Unload all the other themes
for (var i = 0; i < themes.length; i++) {
let styleSheet = document.getElementById(themes[i]);
@ -452,6 +457,7 @@ export function setTheme(theme: string, forceReload: boolean = false) {
document
.getElementById('default-dark')
.setAttribute('disabled', 'disabled');
// Load the theme dynamically
let cssLoc = `/static/assets/css/themes/${theme}.min.css`;
loadCss(theme, cssLoc);