Skip to content

Commit

Permalink
feat: flesh out createHtml with dummy data
Browse files Browse the repository at this point in the history
  • Loading branch information
kometenstaub committed Mar 10, 2022
1 parent c0108c8 commit 279f1de
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/diff_view.ts
@@ -1,8 +1,10 @@
import { html } from 'diff2html';
import { App, Modal, TFile } from 'obsidian';
import { App, Modal, Notice, TFile } from 'obsidian';
import type OpenSyncHistoryPlugin from './main';

export default class DiffView extends Modal {
parser: DOMParser;

constructor(
private plugin: OpenSyncHistoryPlugin,
public app: App,
Expand All @@ -12,12 +14,25 @@ export default class DiffView extends Modal {
this.plugin = plugin;
this.app = app;
this.file = file;
this.parser = new DOMParser()
this.createHtml();
}

createHtml() {
async createHtml() {
const versions = this.plugin.diff_utils.getVersions(this.file);
// need to choose the two versions somehow
const [v1, v2] = [10, 20] // dummy versions
const { getContent, getUnifiedDiff } = this.plugin.diff_utils
const [c1, c2] = [await getContent(v1), await getContent(v2)]
this.titleEl.setText('Diff view');
//this.contentEl.
const uDiff = await getUnifiedDiff(c1, c2)
if (uDiff !== null) {
const diff = html(uDiff)
const parsedHtml = this.parser.parseFromString(diff, 'text/html')
this.contentEl.append(parsedHtml)
} else {
new Notice('Something went wrong.')
}

}
}

0 comments on commit 279f1de

Please sign in to comment.