Removed Floating timer -> Status Bar
This commit is contained in:
67
src/view.ts
67
src/view.ts
@@ -12,6 +12,12 @@ import FocusTaskPlugin from './main';
|
||||
export class FocusTaskView extends ItemView {
|
||||
plugin: FocusTaskPlugin;
|
||||
currentFilter: string = 'all';
|
||||
|
||||
// References to elements that need frequent updates
|
||||
private timerTimeEl: HTMLElement | null = null;
|
||||
private progressBarEl: HTMLElement | null = null;
|
||||
private actualTimeEl: HTMLElement | null = null;
|
||||
private pauseBtnEl: HTMLElement | null = null;
|
||||
|
||||
constructor(leaf: WorkspaceLeaf, plugin: FocusTaskPlugin) {
|
||||
super(leaf);
|
||||
@@ -34,10 +40,47 @@ export class FocusTaskView extends ItemView {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
// Light update - only updates timer display without rebuilding DOM
|
||||
updateTimerDisplay() {
|
||||
if (!this.timerTimeEl) return;
|
||||
|
||||
// Update timer text
|
||||
this.timerTimeEl.textContent = this.plugin.formatTime(this.plugin.currentTimerSeconds);
|
||||
|
||||
// Update progress bar
|
||||
if (this.progressBarEl) {
|
||||
let progressPercent = 0;
|
||||
if (this.plugin.isBreakMode) {
|
||||
const breakDuration = this.plugin.pomodoroCount % this.plugin.settings.longBreakInterval === 0
|
||||
? this.plugin.settings.longBreakMinutes * 60
|
||||
: this.plugin.settings.pomodoroBreakMinutes * 60;
|
||||
progressPercent = ((breakDuration - this.plugin.currentTimerSeconds) / breakDuration) * 100;
|
||||
} else {
|
||||
const workDuration = this.plugin.settings.pomodoroWorkMinutes * 60;
|
||||
progressPercent = ((workDuration - this.plugin.currentTimerSeconds) / workDuration) * 100;
|
||||
}
|
||||
this.progressBarEl.style.width = `${Math.min(Math.max(progressPercent, 0), 100)}%`;
|
||||
}
|
||||
|
||||
// Update actual time display
|
||||
if (this.actualTimeEl && this.plugin.activeTaskId) {
|
||||
const task = this.plugin.data.tasks.find(t => t.id === this.plugin.activeTaskId);
|
||||
if (task) {
|
||||
this.actualTimeEl.textContent = `Actual: ${this.plugin.formatTimeHuman(task.actualMinutes)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
const container = this.containerEl.children[1];
|
||||
container.empty();
|
||||
container.addClass('focus-task-container');
|
||||
|
||||
// Reset element references
|
||||
this.timerTimeEl = null;
|
||||
this.progressBarEl = null;
|
||||
this.actualTimeEl = null;
|
||||
this.pauseBtnEl = null;
|
||||
|
||||
// Header
|
||||
this.renderHeader(container);
|
||||
@@ -109,16 +152,16 @@ export class FocusTaskView extends ItemView {
|
||||
|
||||
activeCard.createEl('div', { cls: 'focus-task-active-task-name', text: task.text });
|
||||
|
||||
// Timer display
|
||||
// Timer display - store reference for updates
|
||||
const timerDisplay = activeCard.createEl('div', { cls: 'focus-task-timer-display' });
|
||||
timerDisplay.createEl('span', {
|
||||
this.timerTimeEl = timerDisplay.createEl('span', {
|
||||
cls: 'focus-task-timer-time',
|
||||
text: this.plugin.formatTime(this.plugin.currentTimerSeconds)
|
||||
});
|
||||
|
||||
// Progress bar
|
||||
// Progress bar - store reference for updates
|
||||
const progressWrap = activeCard.createEl('div', { cls: 'focus-task-progress-wrap' });
|
||||
const progress = progressWrap.createEl('div', { cls: 'focus-task-progress-bar' });
|
||||
this.progressBarEl = progressWrap.createEl('div', { cls: 'focus-task-progress-bar' });
|
||||
|
||||
let progressPercent = 0;
|
||||
if (this.plugin.isBreakMode) {
|
||||
@@ -131,22 +174,22 @@ export class FocusTaskView extends ItemView {
|
||||
progressPercent = ((workDuration - this.plugin.currentTimerSeconds) / workDuration) * 100;
|
||||
}
|
||||
|
||||
progress.style.width = `${Math.min(Math.max(progressPercent, 0), 100)}%`;
|
||||
if (progressPercent >= 100) progress.addClass('focus-task-overtime');
|
||||
this.progressBarEl.style.width = `${Math.min(Math.max(progressPercent, 0), 100)}%`;
|
||||
if (progressPercent >= 100) this.progressBarEl.addClass('focus-task-overtime');
|
||||
|
||||
// Time info
|
||||
// Time info - store reference for actual time updates
|
||||
if (!this.plugin.isBreakMode) {
|
||||
const timeInfo = activeCard.createEl('div', { cls: 'focus-task-time-info' });
|
||||
timeInfo.createEl('span', { text: `Est: ${this.plugin.formatTimeHuman(task.estimatedMinutes)}` });
|
||||
timeInfo.createEl('span', { text: `Actual: ${this.plugin.formatTimeHuman(task.actualMinutes)}` });
|
||||
this.actualTimeEl = timeInfo.createEl('span', { text: `Actual: ${this.plugin.formatTimeHuman(task.actualMinutes)}` });
|
||||
}
|
||||
|
||||
// Controls
|
||||
const controls = activeCard.createEl('div', { cls: 'focus-task-active-controls' });
|
||||
|
||||
const pauseBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-secondary' });
|
||||
pauseBtn.innerHTML = this.plugin.isTimerRunning ? '⏸ Pause' : '▶ Resume';
|
||||
pauseBtn.addEventListener('click', () => this.plugin.toggleTimer());
|
||||
this.pauseBtnEl = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-secondary' });
|
||||
this.pauseBtnEl.innerHTML = this.plugin.isTimerRunning ? '⏸ Pause' : '▶ Resume';
|
||||
this.pauseBtnEl.addEventListener('click', () => this.plugin.toggleTimer());
|
||||
|
||||
if (!this.plugin.isBreakMode) {
|
||||
const completeBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-success' });
|
||||
@@ -316,4 +359,4 @@ export class FocusTaskView extends ItemView {
|
||||
this.plugin.deleteTask(task.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user