Skip to content

Commit b54d41a

Browse files
committed
Refactor, import APIClient and ExportType
1 parent 4841785 commit b54d41a

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/api.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import * as apiClient from '@hackmd/api';
2-
export const apiExportType = apiClient.ExportType;
3-
export const API = new apiClient.default();
1+
import APIClient from '@hackmd/api';
2+
import { ExportType } from '@hackmd/api';
3+
const API = new APIClient();
4+
5+
export { API, ExportType };
6+
47

src/commands/treeView.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { HackMDTreeViewProvider } from './../tree/index';
44
import { NoteTreeNode } from './../tree/nodes';
55
import { MdTextDocumentContentProvider } from './../mdTextDocument';
66
import { refreshHistoryList } from './../utils';
7-
import { API, apiExportType } from './../api';
7+
import { API, ExportType } from './../api';
88

99
export async function registerTreeViewCommands(context: vscode.ExtensionContext, store: Store) {
1010
const hackMDTreeViewProvider = new HackMDTreeViewProvider(store);
@@ -13,7 +13,7 @@ export async function registerTreeViewCommands(context: vscode.ExtensionContext,
1313

1414
context.subscriptions.push(vscode.commands.registerCommand('clickTreeItem', async (label, noteId) => {
1515
if (label && noteId) {
16-
const content = await API.exportString(noteId, apiExportType.MD);
16+
const content = await API.exportString(noteId, ExportType.MD);
1717
if (content) {
1818
const uri = vscode.Uri.parse(`hackmd:${label}.md#${noteId}`);
1919
const doc = await vscode.workspace.openTextDocument(uri);
@@ -25,7 +25,7 @@ export async function registerTreeViewCommands(context: vscode.ExtensionContext,
2525
context.subscriptions.push(vscode.commands.registerCommand('note.showPreview', async (node: NoteTreeNode) => {
2626
const noteNode = node;
2727
if (noteNode.label && noteNode.noteId) {
28-
const content = await API.exportString(noteNode.noteId, apiExportType.MD);
28+
const content = await API.exportString(noteNode.noteId, ExportType.MD);
2929
if (content) {
3030
const uri = vscode.Uri.parse(`hackmd:${noteNode.label}.md#${noteNode.noteId}`);
3131
vscode.commands.executeCommand('markdown.showPreview', uri);
@@ -36,7 +36,7 @@ export async function registerTreeViewCommands(context: vscode.ExtensionContext,
3636
context.subscriptions.push(vscode.commands.registerCommand('note.showPreviewAndEditor', async (node: NoteTreeNode) => {
3737
const noteNode = node;
3838
if (noteNode.label && noteNode.noteId) {
39-
const content = await API.exportString(noteNode.noteId,apiExportType.MD);
39+
const content = await API.exportString(noteNode.noteId,ExportType.MD);
4040
if (content) {
4141
const uri = vscode.Uri.parse(`hackmd:${noteNode.label}.md#${noteNode.noteId}`);
4242
const doc = await vscode.workspace.openTextDocument(uri);

src/mdTextDocument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as vscode from 'vscode';
2-
import { API, apiExportType } from './api';
2+
import { API, ExportType } from './api';
33

44
export class MdTextDocumentContentProvider implements vscode.TextDocumentContentProvider {
55
async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
66
const noteId = uri.fragment;
7-
const content = await API.exportString(noteId, apiExportType.MD);
7+
const content = await API.exportString(noteId, ExportType.MD);
88
return content;
99
}
1010
}

0 commit comments

Comments
 (0)