22// Import the module and reference it with the alias vscode in your code below
33import axios from 'axios' ;
44import * as apiClient from '@hackmd/api' ;
5- import { MdTreeItemProvider } from './mdTreeView' ;
65import { MdTextDocumentContentProvider } from './mdTextDocument' ;
76import * as vscode from 'vscode' ;
87import * as markdownitContainer from 'markdown-it-container' ;
98import * as S from 'string' ;
109import { store } from './store'
1110import { initializeStorage } from './store/storage'
1211import * as Prism from 'prismjs' ;
12+ import { checkLogin , login , refreshHistoryList } from './tree/index' ;
13+ import { HackMDTreeViewProvider } from './tree/index'
1314
1415require ( 'prismjs/components/prism-wiki' ) ;
1516require ( 'prismjs/components/prism-haskell' ) ;
@@ -230,43 +231,6 @@ let highlight;
230231const API = new apiClient . default ( ) ;
231232axios . defaults . withCredentials = true ;
232233
233-
234- const refreshHistoryList = async ( context ) => {
235- if ( await checkLogin ( ) ) {
236- store . history = ( await API . getHistory ( ) ) . history ;
237- context . globalState . update ( 'history' , store . history ) ;
238- } else {
239- store . history = [ { } ] ;
240- context . globalState . update ( 'history' , [ { } ] ) ;
241- }
242- } ;
243-
244- const checkLogin = async ( ) => {
245- return ( await API . getMe ( ) ) . status === 'ok' ;
246- } ;
247-
248- const login = async ( context : vscode . ExtensionContext ) => {
249- const { email, password } = getLoginCredential ( context ) ;
250- if ( ! email || ! password ) {
251- vscode . window . showInformationMessage ( 'Please enter your email and password to use HackMD extension!' )
252- return ;
253- }
254- await API . login ( email , password ) ;
255- if ( await checkLogin ( ) ) {
256- store . isLogin = true ;
257- context . globalState . update ( 'isLogin' , true ) ;
258- vscode . window . showInformationMessage ( 'Successfully login!' ) ;
259- } else {
260- vscode . window . showInformationMessage ( 'Wrong email or password, please enter again' ) ;
261- }
262- } ;
263-
264- const getLoginCredential = ( context : vscode . ExtensionContext ) => {
265- const email : string = context . globalState . get ( 'email' ) ;
266- const password : string = context . globalState . get ( 'password' ) ;
267- return { email, password } ;
268- } ;
269-
270234export async function activate ( context : vscode . ExtensionContext ) {
271235 initializeStorage ( context ) ;
272236 context . subscriptions . push ( vscode . commands . registerCommand ( 'HackMD.login' , async ( ) => {
@@ -304,7 +268,7 @@ export async function activate(context: vscode.ExtensionContext) {
304268
305269 context . globalState . update ( 'email' , email ) ;
306270 context . globalState . update ( 'password' , password ) ;
307-
271+
308272 await login ( context ) ;
309273 await refreshHistoryList ( context ) ;
310274 } ) ) ;
@@ -321,12 +285,12 @@ export async function activate(context: vscode.ExtensionContext) {
321285 await refreshHistoryList ( context ) ;
322286 } ) ) ;
323287
324- const treeViewProvider = new MdTreeItemProvider ( store ) ;
288+ const hackMDTreeViewProvider = new HackMDTreeViewProvider ( store ) ;
325289 context . subscriptions . push (
326- vscode . window . registerTreeDataProvider ( 'mdTreeItems' , treeViewProvider )
290+ vscode . window . registerTreeDataProvider ( 'mdTreeItems' , hackMDTreeViewProvider )
327291 ) ;
328292 context . subscriptions . push (
329- vscode . commands . registerCommand ( 'treeView.refreshList' , ( ) => treeViewProvider . refresh ( ) )
293+ vscode . commands . registerCommand ( 'treeView.refreshList' , ( ) => hackMDTreeViewProvider . refresh ( ) )
330294 ) ;
331295
332296 context . subscriptions . push ( vscode . workspace . registerTextDocumentContentProvider ( 'hackmd' , new MdTextDocumentContentProvider ( ) ) ) ;
0 commit comments