Skip to content

Commit

Permalink
Closes #95 and closes #97
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbinBaauw committed Jan 14, 2019
1 parent 3309336 commit f81e217
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 112 deletions.
6 changes: 0 additions & 6 deletions cshub-client/src/components/posts/Post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,6 @@ import {EditPostReturnTypes} from "../../../../cshub-shared/src/api-calls/pages"
header: "Edited post",
text: "Post was edited successfully"
});
const postHashCacheItemID = `POSTDRAFT_${this.postHash === -1 ? "def" : this.postHash}`;
localForage.setItem<Delta>(postHashCacheItemID, null)
.then(() => {
logStringConsole("Undrafted current post", "post");
});
} else {
uiState.setNotificationDialogState({
on: true,
Expand Down
60 changes: 5 additions & 55 deletions cshub-client/src/components/quill/MarkdownEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@
<div>
<v-container style="max-width: inherit">
<v-layout>
<v-flex xs6 style="padding-right: 20px">
<v-textarea
title="Input"
id="input"
auto-grow
autofocus
label="Your input"
spellcheck="false"
v-model="input"
@keyup="renderMarkdown"
@keydown.tab.prevent="tabHandler"
placeholder="Type here">
</v-textarea>
</v-flex>
<v-flex xs6 style="padding-left: 20px">
<v-flex xs12 style="padding-left: 20px">
<p v-html="output" class="markdown-body"></p>
</v-flex>
</v-layout>
Expand Down Expand Up @@ -44,16 +30,8 @@
*/
@Prop(Array) private initialValue: object[];
private input = "";
private output = "";
/**
* Lifecycle hooks
*/
private mounted() {
this.renderMarkdown();
}
/**
* Computed properties
*/
Expand All @@ -71,49 +49,21 @@
@Watch("markdownDialogState")
private markdownDialogStateChanged() {
if (this.markdownDialogState.open) {
this.input = "";
let input = "";
for (let i = 0; i < this.markdownDialogState.blots.length; i++) {
const currBlot = this.markdownDialogState.blots[i];
const currText = (currBlot.domNode as any).innerText;
if (currText !== "") {
this.input += currText;
input += currText;
if (currText !== "\n" && i !== this.markdownDialogState.blots.length - 1) {
this.input += "\n";
input += "\n";
}
}
}
this.renderMarkdown();
} else {
for (let i = 0; i < this.markdownDialogState.blots.length; i++) {
const currBlot = this.markdownDialogState.blots[i];
currBlot.deleteAt(0, currBlot.length());
if (i === 0) {
// It seems like parchment has a bug, it only starts properly inserting from the second line, so adding a fake word here
currBlot.insertAt(0, `xxx\n${this.input}`);
}
}
this.output = getMarkdownParser(window).render(input);
}
}
/**
* Methods
*/
private renderMarkdown() {
this.output = getMarkdownParser(window).render(this.input);
}
private tabHandler(event: Event) {
const text = this.input;
const originalSelectionStart = (event.target as any).selectionStart;
const textStart = text.slice(0, originalSelectionStart);
const textEnd = text.slice(originalSelectionStart);
this.input = `${textStart}\t${textEnd}`;
(event.target as any).selectionEnd = (event.target as any).selectionStart = originalSelectionStart + 1;
}
}
</script>

Expand Down
52 changes: 1 addition & 51 deletions cshub-client/src/components/quill/Quill.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,14 @@
<v-btn fab small depressed color="primary" class="ql-tooltip" id="markdownTooltip" @click="openMarkdownDialog">
<v-icon>fas fa-edit</v-icon>
</v-btn>
<v-dialog v-model="loadDraftDialog" persistent max-width="290">
<v-card>
<v-card-title class="headline">Open draft?</v-card-title>
<v-card-text>A draft of this post was saved. Load this draft? If you don't load the draft, it will be
discarded once you type.
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="green darken-1" flat @click="loadDraft(true)">Load</v-btn>
<v-btn color="green darken-1" flat @click="loadDraft(false)">Discard</v-btn>
</v-card-actions>
</v-card>
</v-dialog>

<v-dialog v-model="markdownDialogState.open" fullscreen hide-overlay transition="dialog-bottom-transition">
<v-card>
<v-toolbar dark color="primary">
<v-btn icon dark @click="closeMarkdownDialog">
<v-icon>fas fa-times</v-icon>
</v-btn>
<v-toolbar-title>Markdown editor</v-toolbar-title>
<v-toolbar-title>Markdown preview</v-toolbar-title>
<v-spacer></v-spacer>
</v-toolbar>
<MarkdownEditor v-if="markdownDialogState"></MarkdownEditor>
Expand Down Expand Up @@ -260,12 +247,6 @@
private socketTypingTimeout: number = null;
private currentEdits: Delta[] = [];
// Drafting related variables
private draftTypingTimeout: number = null;
private draftValue: Delta = null;
private loadDraftDialog = false;
private postHashCacheItemID = "";
// Table related variables
private tableMenuOpen = false;
private tableActions = TableActions;
Expand Down Expand Up @@ -357,17 +338,6 @@
(window as any).katex = katex;
if (this.editorSetup.allowEdit) {
this.postHashCacheItemID = `POSTDRAFT_${this.editorSetup.postHash === -1 ? "def" : this.editorSetup.postHash}`;
localForage.getItem<Delta>(this.postHashCacheItemID)
.then((cachedDraft: Delta) => {
if (cachedDraft !== null) {
this.loadDraftDialog = true;
this.draftValue = cachedDraft;
}
});
}
logStringConsole("Mounted quillInstance with edit: " + this.editorSetup.allowEdit);
this.editorId = idGenerator();
Expand Down Expand Up @@ -423,16 +393,6 @@
}
private loadDraft(load: boolean) {
if (load) {
this.editor.setContents(this.draftValue);
} else {
this.draftValue = null;
}
this.loadDraftDialog = false;
}
private getDelta() {
return this.editor.getContents();
}
Expand Down Expand Up @@ -513,16 +473,6 @@
}
private textChanged(delta: Delta, oldContents: Delta, source: Sources) {
clearTimeout(this.draftTypingTimeout);
this.draftTypingTimeout = setTimeout(() => {
if (this.editor !== null) {
localForage.setItem<Delta>(this.postHashCacheItemID, this.getDelta())
.then(() => {
logStringConsole("Drafted current post", "textchanged quillInstance");
});
}
}, 1000);
if (source === "user") {
this.currentEdits.push(delta);
}
Expand Down

0 comments on commit f81e217

Please sign in to comment.