Skip to content

Commit 902e521

Browse files
committed
型エラー修正
1 parent f0fc336 commit 902e521

File tree

8 files changed

+43
-44
lines changed

8 files changed

+43
-44
lines changed

src/commands/compose.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { qiitaItemsProvider } from '../explorers/qiitaItems';
66
import { tagQuickPickCreator, validateTagQuickPick } from '../quickpicks/tagQuickPick';
77
import { titleInputBoxCreator, validateTitleInputBox } from '../quickpicks/titleInputBox';
88
import { privateLabel, visibilityQuickPickCreator } from '../quickpicks/visibilityQuickPick';
9-
import { itemsStore } from '../stores/itemsStore';
109
import { handleErrorMessage } from '../utils/errorHandler';
1110
import { getFilenameFromPath } from '../utils/getFilenameFromPath';
1211

@@ -85,8 +84,7 @@ export async function compose (resource?: Uri) {
8584

8685
try {
8786
const item = await client.createItem(options);
88-
await itemsStore.refreshItems();
89-
qiitaItemsProvider.refresh();
87+
await qiitaItemsProvider.refreshItems();
9088

9189
const openInBrowser = localize(
9290
'commands.compose.openInBrowser',

src/commands/deleteItem.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { window } from 'vscode';
33
import * as nls from 'vscode-nls';
44
import { client } from '../client';
55
import { qiitaItemsProvider } from '../explorers/qiitaItems';
6-
import { itemsStore } from '../stores/itemsStore';
76
import { handleErrorMessage } from '../utils/errorHandler';
87

98
const localize = nls.loadMessageBundle();
@@ -36,8 +35,7 @@ export async function deleteItem (resource: { item: Item }) {
3635

3736
try {
3837
await client.deleteItem(resource.item.id);
39-
await itemsStore.refreshItems();
40-
qiitaItemsProvider.refresh();
38+
await qiitaItemsProvider.refreshItems();
4139

4240
return window.showInformationMessage(localize(
4341
'commands.deleteItem.success',

src/commands/editTags.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as nls from 'vscode-nls';
44
import { client } from '../client';
55
import { qiitaItemsProvider } from '../explorers/qiitaItems';
66
import { makeQuickPickItemFromTag, tagQuickPickCreator, validateTagQuickPick } from '../quickpicks/tagQuickPick';
7-
import { itemsStore } from '../stores/itemsStore';
87
import { handleErrorMessage } from '../utils/errorHandler';
98

109
const localize = nls.loadMessageBundle();
@@ -49,8 +48,7 @@ export async function editTags (resource: { item: Item }) {
4948
try {
5049
quickPick.hide();
5150
await updater(item, quickPick.selectedItems);
52-
await itemsStore.refreshItems();
53-
qiitaItemsProvider.refresh();
51+
await qiitaItemsProvider.refreshItems();
5452

5553
return window.showInformationMessage(localize(
5654
'commands.editTags.success',

src/commands/editTitle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function editTitle (resource: { item: Item }) {
3131
tags: item.tags,
3232
title: inputBox.value,
3333
});
34-
qiitaItemsProvider.refresh();
34+
qiitaItemsProvider.refreshItems();
3535

3636
return window.showInformationMessage(localize(
3737
'commands.editTitle.success',

src/commands/expandItems.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { qiitaItemsProvider } from '../explorers/qiitaItems';
2-
import { itemsStore } from '../stores/itemsStore';
32

43
export async function expandItems () {
54
try {
6-
if (!itemsStore.done) {
7-
await itemsStore.expandItems();
8-
qiitaItemsProvider.refresh();
5+
if (!qiitaItemsProvider.done) {
6+
await qiitaItemsProvider.expandItems();
97
}
108
} catch (e) {
119
console.error(e);

src/commands/makePublic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function makePublic (resource: { item: Item }) {
4747
tags: resource.item.tags,
4848
private: false,
4949
});
50-
qiitaItemsProvider.refresh();
50+
qiitaItemsProvider.refreshItems();
5151

5252
return window.showInformationMessage(localize(
5353
'commands.makePublic.success',

src/explorers/qiitaItems.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,51 @@ import { QiitaItem } from './models/qiitaItemsNode';
88

99
const localize = nls.loadMessageBundle();
1010

11-
class QiitaItemsProvider implements TreeDataProvider<TreeItem> {
12-
private _onDidChangeTreeData: EventEmitter<TreeItem|undefined> = new EventEmitter<TreeItem|undefined>();
13-
public readonly onDidChangeTreeData: Event<TreeItem|undefined> = this._onDidChangeTreeData.event;
11+
type NodeTypes = ExpandItems|QiitaItem;
12+
13+
class QiitaItemsProvider implements TreeDataProvider<NodeTypes> {
14+
/** TreeDataProviderの変更を制御するためのEventEmitter */
15+
private _onDidChangeTreeData: EventEmitter<NodeTypes|undefined> = new EventEmitter<NodeTypes|undefined>();
16+
17+
/** 外部から参照するためのプロパティ */
18+
public readonly onDidChangeTreeData: Event<NodeTypes|undefined> = this._onDidChangeTreeData.event;
1419

1520
/** 取得した投稿 */
16-
protected items: Item[] = [];
21+
public items: Item[] = [];
1722

1823
/** 全件取得したかどうか */
19-
protected done = false;
24+
public done = false;
2025

2126
/** 自分の投稿の配列を返すイテラブル */
2227
protected itemsIterable = client.fetchMyItems({ page: 1, per_page: 60 });
2328

2429
/**
2530
* ツリーデータを更新
2631
*/
27-
public async refresh () {
32+
protected async refresh () {
2833
this._onDidChangeTreeData.fire();
2934
}
3035

36+
/**
37+
* イテラブルを初期化して最初のページを再取得
38+
*/
39+
public async refreshItems () {
40+
const { value: items, done } = await this.itemsIterable.next('reset');
41+
this.items = items;
42+
this.done = done;
43+
this.refresh();
44+
}
45+
46+
/**
47+
* イテラブルのnextを呼び出し
48+
*/
49+
public async expandItems () {
50+
const { value: items, done } = await this.itemsIterable.next();
51+
this.items.concat(items);
52+
this.done = done;
53+
this.refresh();
54+
}
55+
3156
/**
3257
* `element` に対応するツリーアイテムを取得
3358
* @param element 取得するelement
@@ -42,13 +67,13 @@ class QiitaItemsProvider implements TreeDataProvider<TreeItem> {
4267
* @param element 取得するelement
4368
*/
4469
public async getChildren (): Promise<(QiitaItem|ExpandItems)[]> {
45-
if (!itemsStore.items || !itemsStore.items.length) {
46-
await itemsStore.refreshItems();
70+
if (!this.items.length) {
71+
await this.refreshItems();
4772
}
4873

4974
const children = [];
5075

51-
for (const item of itemsStore.items) {
76+
for (const item of this.items) {
5277
const command = {
5378
command: 'qiita.openItem',
5479
title: localize('commands.openItem.title', '開く'),
@@ -59,30 +84,12 @@ class QiitaItemsProvider implements TreeDataProvider<TreeItem> {
5984
}
6085

6186
// アイテムが最後まで読み込まれていない場合、「さらに読み込む...」を挿入する
62-
if (!itemsStore.done) {
87+
if (!this.done) {
6388
children.push(new ExpandItems(TreeItemCollapsibleState.None));
6489
}
6590

6691
return children;
6792
}
68-
69-
/**
70-
* イテラブルを初期化して最初のページを再取得
71-
*/
72-
public async refreshItems () {
73-
const { value: items, done } = await this.itemsIterable.next('reset');
74-
this.items = items;
75-
this.done = done;
76-
}
77-
78-
/**
79-
* イテラブルのnextを呼び出し
80-
*/
81-
public async expandItems () {
82-
const { value: items, done } = await this.itemsIterable.next();
83-
this.items.concat(items);
84-
this.done = done;
85-
}
8693
}
8794

8895
export const qiitaItemsProvider = new QiitaItemsProvider();

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ export function deactivate () {
4848
export const refreshUserState = async (e: ConfigurationChangeEvent) => {
4949
if (e.affectsConfiguration('qiita.token')) {
5050
client.setToken(workspace.getConfiguration('qiita').get('token') || '');
51-
await qiitaItemsProvider.refresh();
51+
await qiitaItemsProvider.refreshItems();
5252
}
5353
};

0 commit comments

Comments
 (0)