import { hydrate } from 'inferno-hydrate';
import { BrowserRouter } from 'inferno-router';
+import { initializeSite } from '../shared/initialize';
import { App } from '../shared/components/app';
+const site = window.isoData.site;
+initializeSite(site);
+
const wrapper = (
<BrowserRouter>
<App site={window.isoData.site} />
import { GetSiteForm, GetSiteResponse } from 'lemmy-js-client';
import process from 'process';
import { Helmet } from 'inferno-helmet';
+import { initializeSite } from '../shared/initialize';
const server = express();
const port = 1234;
lang,
};
+ initializeSite(site);
+ const user = site.my_user;
+ const userTheme =
+ user &&
+ user.theme &&
+ `
+ <link
+ rel="stylesheet"
+ type="text/css"
+ href="/static/assets/css/themes/${user.theme}.min.css"
+ />
+ `;
+
const wrapper = (
<StaticRouter location={req.url} context={isoData}>
<App site={isoData.site} />
<!-- Styles -->
<link rel="stylesheet" type="text/css" href="/static/styles/styles.css" />
+ ${userTheme || ''}
+ ${
+ userTheme
+ ? ''
+ : `
<link rel="stylesheet" type="text/css" href="/static/assets/css/themes/litely.min.css" id="default-light" media="(prefers-color-scheme: light)" />
<link rel="stylesheet" type="text/css" href="/static/assets/css/themes/darkly.min.css" id="default-dark" media="(prefers-color-scheme: no-preference), (prefers-color-scheme: dark)" />
+ `
+ }
</head>
<body ${helmet.bodyAttributes.toString()}>
<b>Javascript is disabled. Actions will not work.</b>
</div>
</noscript>
-
+
<div id='root'>${root}</div>
<script defer src='/static/js/client.js'></script>
</body>
import { Footer } from '../../shared/components/footer';
import { Symbols } from '../../shared/components/symbols';
import { GetSiteResponse } from 'lemmy-js-client';
+import { UserService } from '../../shared/services';
import './styles.scss';
export interface AppProps {
constructor(props: any, context: any) {
super(props, context);
}
-
render() {
return (
<>
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
-
- // The login
- // TODO this needs some work
- UserService.Instance.user = this.props.site.my_user;
- i18n.changeLanguage(getLanguage());
- if (UserService.Instance.user) {
- setTheme(UserService.Instance.user.theme);
- }
-
- // if (!!this.props.site.my_user) {
- // UserService.Instance.this.props.site.my_user);
- // // UserService.Instance.user = this.props.site.my_user;
- // } else {
- // UserService.Instance.setUser(undefined);
- // }
}
componentDidMount() {
--- /dev/null
+import { GetSiteResponse } from 'lemmy-js-client';
+import { UserService } from './services';
+import { i18n } from './i18next';
+import { getLanguage } from './utils';
+
+export const initializeSite = (site: GetSiteResponse) => {
+ UserService.Instance.user = site.my_user;
+ i18n.changeLanguage(getLanguage());
+};
}
export function setTheme(theme: string, forceReload: boolean = false) {
- if (isBrowser() && (theme !== 'browser' || forceReload)) {
- // This is only run on a force reload
- if (theme == 'browser') {
- theme = 'darkly';
- }
+ if (!isBrowser()) {
+ return;
+ }
+ if (theme === 'browser' && !forceReload) {
+ return;
+ }
+ // 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]);
- if (styleSheet) {
- styleSheet.setAttribute('disabled', 'disabled');
- }
+ // Unload all the other themes
+ for (var i = 0; i < themes.length; i++) {
+ let styleSheet = document.getElementById(themes[i]);
+ if (styleSheet) {
+ styleSheet.setAttribute('disabled', 'disabled');
}
-
- document
- .getElementById('default-light')
- .setAttribute('disabled', 'disabled');
- document
- .getElementById('default-dark')
- .setAttribute('disabled', 'disabled');
-
- // Load the theme dynamically
- let cssLoc = `/static/assets/css/themes/${theme}.min.css`;
- loadCss(theme, cssLoc);
- document.getElementById(theme).removeAttribute('disabled');
}
+
+ document
+ .getElementById('default-light')
+ ?.setAttribute('disabled', 'disabled');
+ document.getElementById('default-dark')?.setAttribute('disabled', 'disabled');
+
+ // Load the theme dynamically
+ let cssLoc = `/static/assets/css/themes/${theme}.min.css`;
+ loadCss(theme, cssLoc);
+ document.getElementById(theme).removeAttribute('disabled');
}
export function loadCss(id: string, loc: string) {