Skip to content

Commit

Permalink
Merge pull request #15 from JosephT5566/master
Browse files Browse the repository at this point in the history
Modify search method
  • Loading branch information
Yukaii authored Aug 19, 2019
2 parents 31657ab + 1eab257 commit 577696d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 42 deletions.
39 changes: 27 additions & 12 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"dependencies": {
"find-free-port": "^2.0.0",
"http-proxy": "^1.17.0",
"ptt-client": "^0.5.2",
"ptt-client": "^0.8.0",
"ws": "^6.2.1"
}
}
35 changes: 6 additions & 29 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import PTT from 'ptt-client';
import key from 'ptt-client/dist/utils/keyboard';
import key from 'ptt-client/dist/utils/keymap';

(global as any).WebSocket = require('ws');

Expand Down Expand Up @@ -122,34 +122,9 @@ async function pickFavorite (): Promise<string> {
}
}

async function searchArticleByPush(boardname: string, push: number): Promise<ArticleListItem[]>
function setSearchCondition(type: string, criteria: string): void
{
let searchedArticles: ArticleListItem[] = await fillPushArray(boardname, push, 10);
return searchedArticles;
}

async function fillPushArray(boardname: string, push: number, articleNum: number, offset: number = 0, articles: ArticleListItem[] = []): Promise<ArticleListItem[]>
{
if (articles.length > articleNum)
{
return articles;
}
else
{
let articlesStore: ArticleListItem[];
let lastsn: number;

articlesStore = await ptt.getArticles(boardname, offset);
lastsn = articlesStore.slice(-1)[0].sn;

let filteredStore = articlesStore.filter((article) =>
{
let pushNumber: string = (article.push === '爆') ? '100' : article.push;
return (Number(pushNumber) >= push);
});
articles.push(...filteredStore);
return fillPushArray(boardname, push, articleNum, lastsn, articles);
}
ptt.setSearchCondition(type, criteria);
}

export async function activate(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -232,6 +207,7 @@ export async function activate(context: vscode.ExtensionContext) {
}));

context.subscriptions.push(vscode.commands.registerCommand('ptt.refresh-article', () => {
ptt.resetSearchCondition();
pttProvider.refresh();
}));

Expand Down Expand Up @@ -264,7 +240,8 @@ export async function activate(context: vscode.ExtensionContext) {
}

vscode.window.showInformationMessage('開始搜尋');
let pushArticles: ArticleListItem[] = await searchArticleByPush(board.boardname, Number(push));
setSearchCondition("push", push);
let pushArticles: ArticleListItem[] = await ptt.getArticles(board.boardname);
vscode.window.showInformationMessage('完成搜尋');

store.add(board.boardname, pushArticles);
Expand Down

0 comments on commit 577696d

Please sign in to comment.