Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic real preview on the side of the edit window #697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ node_modules
/lib/jekyll-admin/public
*.gem
.DS_Store
/vendor/
8 changes: 8 additions & 0 deletions spec/fixtures/site/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ foo: bar
---

# Test Page

test

test

test

toto
47 changes: 47 additions & 0 deletions src/components/PreviewPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';

export function PreviewPanel({ previewUrl }) {
// Note : side effect for preview button, layout, and doctitle class
return (
<div className="preview-panel">
<div className="header">
<button
type="button"
className="btn btn-light btn-close"
aria-label="Close"
onClick={() =>
document.getElementById('doctitle').classList.remove('preview')
}
>
</button>
<h3 className="title">Preview</h3>
<button
type="button"
className="btn btn-light btn-refresh"
aria-label="Refresh"
onClick={() => {
var iframe = document.getElementById('preview-iframe');
iframe.src = iframe.src;
}}
>
</button>
</div>
<iframe id="preview-iframe" src={previewUrl} className="preview-page" />
</div>
);
}

export function PreviewButton({}) {
return (
<button
className="btn btn-active btn-view btn-fat"
onClick={() =>
document.getElementById('doctitle').classList.add('preview')
}
>
Side Preview
</button>
);
}
69 changes: 37 additions & 32 deletions src/containers/views/DocumentEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { clearErrors } from '../../ducks/utils';
import { preventDefault, getDocumentTitle } from '../../utils/helpers';
import { ADMIN_PREFIX } from '../../constants';

import { PreviewButton, PreviewPanel } from '../../components/PreviewPanel';
import translations from '../../translations';
const { getLeaveMessage, getDeleteMessage, getNotFoundMessage } = translations;

Expand Down Expand Up @@ -123,44 +124,48 @@ export class DocumentEdit extends Component {

return (
<DocumentTitle title={document_title}>
<HotKeys handlers={keyboardHandlers} className="single">
<HotKeys handlers={keyboardHandlers} className="single" id="doctitle">
{errors.length > 0 && <Errors errors={errors} />}

<div className="content-header">
<Breadcrumbs type={collection} splat={directory} />
</div>
<div className="edit-panel">
<div className="content-header">
<Breadcrumbs type={collection} splat={directory} />
</div>

<div className="content-wrapper">
<MarkdownPageBody
type={collection}
path={name}
title={title}
body={raw_content}
updatePath={updatePath}
updateTitle={updateTitle}
updateBody={updateBody}
onSave={this.handleClickSave}
metafields={{ title, path: name, raw_content, ...front_matter }}
staticmetafields={front_matter_defaults}
/>
<div className="content-side">
<Button
onClick={this.handleClickSave}
type="save"
active={fieldChanged}
triggered={updated}
block
/>
<Button to={http_url} type="view" active block />
<Splitter />
<Button
onClick={this.handleClickDelete}
type="delete"
active
block
<div className="content-wrapper">
<MarkdownPageBody
type={collection}
path={name}
title={title}
body={raw_content}
updatePath={updatePath}
updateTitle={updateTitle}
updateBody={updateBody}
onSave={this.handleClickSave}
metafields={{ title, path: name, raw_content, ...front_matter }}
staticmetafields={front_matter_defaults}
/>
<div className="content-side">
<Button
onClick={this.handleClickSave}
type="save"
active={fieldChanged}
triggered={updated}
block
/>
<Button to={http_url} type="view" active block />
<PreviewButton />
<Splitter />
<Button
onClick={this.handleClickDelete}
type="delete"
active
block
/>
</div>
</div>
</div>
<PreviewPanel previewUrl={http_url} />
</HotKeys>
</DocumentTitle>
);
Expand Down
82 changes: 44 additions & 38 deletions src/containers/views/DraftEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { clearErrors } from '../../ducks/utils';
import { preventDefault, getDocumentTitle } from '../../utils/helpers';
import { ADMIN_PREFIX } from '../../constants';

import { PreviewButton, PreviewPanel } from '../../components/PreviewPanel';
import translations from '../../translations';
const {
getLeaveMessage,
Expand Down Expand Up @@ -143,49 +144,54 @@ export class DraftEdit extends Component {

return (
<DocumentTitle title={document_title}>
<HotKeys handlers={keyboardHandlers} className="single">
<HotKeys handlers={keyboardHandlers} className="single" id="doctitle">
{errors.length > 0 && <Errors errors={errors} />}
<div className="content-header">
<Breadcrumbs type="drafts" splat={directory} />
</div>

<div className="content-wrapper">
<MarkdownPageBody
type="drafts"
path={name}
title={title}
body={raw_content}
updatePath={updatePath}
updateBody={updateBody}
updateTitle={updateTitle}
onSave={this.handleClickSave}
metafields={{ title, raw_content, path: name, ...front_matter }}
staticmetafields={front_matter_defaults}
/>
<div className="content-side">
<Button
onClick={this.handleClickSave}
type="save"
active={fieldChanged}
triggered={updated}
block
/>
<Button to={http_url} type="view" active block />
<Splitter />
<Button
onClick={() => this.handleClickPublish(path)}
type="publish"
active
block
/>
<Button
onClick={() => this.handleClickDelete(name)}
type="delete"
active
block
<div className="edit-panel">
<div className="content-header">
<Breadcrumbs type="drafts" splat={directory} />
</div>

<div className="content-wrapper">
<MarkdownPageBody
type="drafts"
path={name}
title={title}
body={raw_content}
updatePath={updatePath}
updateBody={updateBody}
updateTitle={updateTitle}
onSave={this.handleClickSave}
metafields={{ title, raw_content, path: name, ...front_matter }}
staticmetafields={front_matter_defaults}
/>
<div className="content-side">
<Button
onClick={this.handleClickSave}
type="save"
active={fieldChanged}
triggered={updated}
block
/>
<Button to={http_url} type="view" active block />
<PreviewButton />
<Splitter />
<Button
onClick={() => this.handleClickPublish(path)}
type="publish"
active
block
/>
<Button
onClick={() => this.handleClickDelete(name)}
type="delete"
active
block
/>
</div>
</div>
</div>
<PreviewPanel previewUrl={http_url} />
</HotKeys>
</DocumentTitle>
);
Expand Down
71 changes: 39 additions & 32 deletions src/containers/views/PageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { preventDefault, getDocumentTitle } from '../../utils/helpers';
import { ADMIN_PREFIX } from '../../constants';

import translations from '../../translations';
import { PreviewButton, PreviewPanel } from '../../components/PreviewPanel';
const { getLeaveMessage, getDeleteMessage } = translations;

export class PageEdit extends Component {
Expand Down Expand Up @@ -110,46 +111,52 @@ export class PageEdit extends Component {
const title = front_matter && front_matter.title ? front_matter.title : '';
const document_title = getDocumentTitle('pages', directory, title || name);

console.log('http_url', http_url);

return (
<DocumentTitle title={document_title}>
<HotKeys handlers={keyboardHandlers} className="single">
<HotKeys handlers={keyboardHandlers} className="single" id="doctitle">
{errors.length > 0 && <Errors errors={errors} />}

<div className="content-header">
<Breadcrumbs type="pages" splat={directory} />
</div>
<div className="edit-panel">
<div className="content-header">
<Breadcrumbs type="pages" splat={directory} />
</div>

<div className="content-wrapper">
<MarkdownPageBody
type="pages"
updateTitle={updateTitle}
updatePath={updatePath}
updateBody={updateBody}
onSave={this.handleClickSave}
path={name}
title={title}
body={raw_content}
metafields={{ title, raw_content, path: name, ...front_matter }}
staticmetafields={front_matter_defaults}
/>
<div className="content-side">
<Button
onClick={this.handleClickSave}
type="save"
active={fieldChanged}
triggered={updated}
block
/>
<Button to={http_url} type="view" active block />
<Splitter />
<Button
onClick={() => this.handleClickDelete(name)}
type="delete"
active
block
<div className="content-wrapper">
<MarkdownPageBody
type="pages"
updateTitle={updateTitle}
updatePath={updatePath}
updateBody={updateBody}
onSave={this.handleClickSave}
path={name}
title={title}
body={raw_content}
metafields={{ title, raw_content, path: name, ...front_matter }}
staticmetafields={front_matter_defaults}
/>
<div className="content-side">
<Button
onClick={this.handleClickSave}
type="save"
active={fieldChanged}
triggered={updated}
block
/>
<Button to={http_url} type="view" active block />
<PreviewButton />
<Splitter />
<Button
onClick={() => this.handleClickDelete(name)}
type="delete"
active
block
/>
</div>
</div>
</div>
<PreviewPanel previewUrl={http_url} />
</HotKeys>
</DocumentTitle>
);
Expand Down
1 change: 1 addition & 0 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import "mdeditor";
@import "button";
@import "staticfiles";
@import "preview";

*, *:before, *:after {
box-sizing: border-box;
Expand Down
Loading