Skip to content

Commit

Permalink
Fetch billability excluded tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaScorpion committed May 22, 2024
1 parent 36e2c5b commit bc3e7f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/TimeChimpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class TimeChimpApi {
public getCompany(): Promise<Company> {
return this.doFetch('/api/company');
}

public getTasks(): Promise<Task[]> {
return this.doFetch('/api/task');
}
}

export interface User {
Expand All @@ -64,3 +68,9 @@ export interface Company {
export interface Theme {
mainColor?: string;
}

export interface Task {
id: number;
name: string;
tagNames?: string[];
}
19 changes: 19 additions & 0 deletions src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ setDefaultOptions({
firstWeekContainsDate: 4,
});

const BILLABILITY_EXCLUDE_TAG = 'billability-exclude';

const api = new TimeChimpApi();

let currentDate = new Date();
let currentUser: User | undefined;
let billabilityExcludedTasks: number[] | undefined;

settingsUpdateEvent.addListener(() => render());

Expand All @@ -35,10 +38,16 @@ chrome.runtime.onMessage.addListener(async (msg: Message) => {
});

async function render(userName?: string) {
// Check if we have the current user info.
if (!currentUser || (userName && userName !== currentUser.userName)) {
currentUser = await getUser(userName);
}

// Check if we have the excluded tasks.
if (!billabilityExcludedTasks) {
billabilityExcludedTasks = await getBillabilityExcludedTaskIds();
}

await addBillabilityChart(currentDate, currentUser);
}

Expand All @@ -58,3 +67,13 @@ function getUser(userName?: string) {
return api.getCurrentUser();
}
}

async function getBillabilityExcludedTaskIds(): Promise<number[]> {
const tasks = (await api.getTasks()).filter(
(t) => t.tagNames?.includes(BILLABILITY_EXCLUDE_TAG),
);
console.debug(
`Billability excluded tasks: ${tasks.map((t) => t.name).join(', ')}`,
);
return tasks.map((t) => t.id);
}

0 comments on commit bc3e7f4

Please sign in to comment.