浏览代码

Adds a focus service (wip)

main
Eric Amodio 1年前
committed by Keith Daulton
父节点
当前提交
6181285a97
共有 2 个文件被更改,包括 100 次插入0 次删除
  1. +10
    -0
      src/container.ts
  2. +90
    -0
      src/plus/focus/focusService.ts

+ 10
- 0
src/container.ts 查看文件

@ -21,6 +21,7 @@ import { GitLabAuthenticationProvider } from './git/remotes/gitlab';
import { RichRemoteProviderService } from './git/remotes/remoteProviderService';
import { LineHoverController } from './hovers/lineHoverController';
import type { RepositoryPathMappingProvider } from './pathMapping/repositoryPathMappingProvider';
import { FocusService } from './plus/focus/focusService';
import { AccountAuthenticationProvider } from './plus/gk/authenticationProvider';
import { ServerConnection } from './plus/gk/serverConnection';
import { IntegrationAuthenticationService } from './plus/integrationAuthentication';
@ -436,6 +437,15 @@ export class Container {
return this._deepLinks;
}
private _focus: FocusService | undefined;
get focus() {
if (this._focus == null) {
this._disposables.push((this._focus = new FocusService(this, new ServerConnection(this))));
}
return this._focus;
}
private _github: Promise<import('./plus/github/github').GitHubApi | undefined> | undefined;
get github() {
if (this._github == null) {

+ 90
- 0
src/plus/focus/focusService.ts 查看文件

@ -0,0 +1,90 @@
import type { Disposable } from 'vscode';
import { Uri } from 'vscode';
import type { Container } from '../../container';
import type { ServerConnection } from '../gk/serverConnection';
export interface FocusItem {
provider: string;
type: 'issue' | 'pr';
id: string;
repositoryId: string;
repositoryName: string;
repositoryOwner: string;
}
export interface EnrichedItem {
id: string;
userId: string;
type: 'pinned' | 'snoozed';
provider: string;
entityType: 'issue' | 'pr';
entityId: string;
repositoryId: string;
repositoryName: string;
repositoryOwner: string;
createdAt: number;
updatedAt: number;
}
export class FocusService implements Disposable {
constructor(
private readonly container: Container,
private readonly connection: ServerConnection,
) {}
dispose(): void {}
async pinItem(item: FocusItem): Promise<EnrichedItem> {
type Result = { data: EnrichedItem };
const rsp = await this.connection.fetch(
Uri.joinPath(this.connection.baseGkApiUri, 'v1/enrich-items/pin').toString(),
{
method: 'POST',
body: JSON.stringify(item),
},
);
const result = (await rsp.json()) as Result;
return result.data;
}
async snoozeItem(item: FocusItem): Promise<EnrichedItem> {
type Result = { data: EnrichedItem };
const rsp = await this.connection.fetch(
Uri.joinPath(this.connection.baseGkApiUri, 'v1/enrich-items/snooze').toString(),
{
method: 'POST',
body: JSON.stringify(item),
},
);
const result = (await rsp.json()) as Result;
return result.data;
}
async getPins(): Promise<EnrichedItem[]> {
const data = await this.getAll();
return data.filter(i => i.type === 'pinned');
}
async getSnoozed(): Promise<EnrichedItem[]> {
const data = await this.getAll();
return data.filter(i => i.type === 'snoozed');
}
async getAll(): Promise<EnrichedItem[]> {
type Result = { data: EnrichedItem[] };
const rsp = await this.connection.fetch(
Uri.joinPath(this.connection.baseGkApiUri, 'v1/enrich-items').toString(),
{
method: 'GET',
},
);
const result = (await rsp.json()) as Result;
return result.data.map(i => i);
}
}

正在加载...
取消
保存