Skip to content

Commit

Permalink
save draft in localstorage (solves #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
gka committed Oct 11, 2017
1 parent fc9b27e commit f5090a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/embed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import comments_tpl from './comments.jst.html';
const textarea = $(`${target} textarea.schnack-body`);
const preview = $(`${target} .schnack-form blockquote.schnack-body`);

const draft = window.localStorage.getItem(`schnack-draft-${slug}`);
if (draft) textarea.value = draft;

const postBtn = $(target + ' .schnack-button');
const previewBtn = $(target + ' .schnack-preview');
const writeBtn = $(target + ' .schnack-write');
Expand Down Expand Up @@ -75,6 +78,10 @@ import comments_tpl from './comments.jst.html';
preview.style.display = 'none';
writeBtn.style.display = 'none';
});

textarea.addEventListener('keyup', () => {
window.localStorage.setItem(`schnack-draft-${slug}`, textarea.value);
});
}
if (data.user) {
const signout = $('a.schnack-signout');
Expand Down

0 comments on commit f5090a4

Please sign in to comment.