* Big upgrades * WIP: Stash * Stash, 30 flow errors left * Downgrade mobx * WIP * When I understand the difference between class and instance methods * 💚 * Fixes: File import Model saving edge cases pinning and starring docs Collection editing Upgrade mobx devtools * Notification settings saving works * Disabled settings * Document mailer * Working notifications * Colletion created notification Ensure not notified for own actions * Tidy up * Document updated event only for document creation Add indexes Notification setting on user creation * Commentary * Fixed: Notification setting on signup * Fix document move / duplicate stale data Add BaseModel.refresh method * Fixes: Title in sidebar not updated after editing document * 💚 * Improve / restore error handling Better handle offline errors * 👕
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
// @flow
|
|
import * as React from 'react';
|
|
import ReactDOMServer from 'react-dom/server';
|
|
import { Helmet } from 'react-helmet';
|
|
import {
|
|
ServerStyleSheet,
|
|
StyleSheetManager,
|
|
ThemeProvider,
|
|
} from 'styled-components';
|
|
import Layout from '../pages/components/Layout';
|
|
import theme from '../../shared/styles/theme';
|
|
|
|
const sheet = new ServerStyleSheet();
|
|
|
|
export default function renderpage(ctx: Object, children: React.Node) {
|
|
let sessions = {};
|
|
try {
|
|
sessions = JSON.parse(ctx.cookies.get('sessions') || '{}');
|
|
} catch (err) {
|
|
console.error(`Sessions cookie could not be parsed: ${err}`);
|
|
}
|
|
|
|
const loggedIn = !!(
|
|
ctx.cookies.get('accessToken') || Object.keys(sessions).length
|
|
);
|
|
|
|
const html = ReactDOMServer.renderToString(
|
|
<StyleSheetManager sheet={sheet.instance}>
|
|
<ThemeProvider theme={theme}>
|
|
<Layout sessions={sessions} loggedIn={loggedIn}>
|
|
{children}
|
|
</Layout>
|
|
</ThemeProvider>
|
|
</StyleSheetManager>
|
|
);
|
|
|
|
// helmet returns an object of meta tags with toString methods, urgh.
|
|
const helmet = Helmet.renderStatic();
|
|
let head = '';
|
|
// $FlowFixMe
|
|
Object.keys(helmet).forEach(key => (head += helmet[key].toString()));
|
|
|
|
ctx.body = `<!DOCTYPE html>\n${html}`
|
|
.replace('{{CSS}}', sheet.getStyleTags())
|
|
.replace('{{HEAD}}', head);
|
|
}
|