Skip to content

Commit c1f26c7

Browse files
committed
feat: update reward
1 parent 6928f11 commit c1f26c7

10 files changed

Lines changed: 1054 additions & 753 deletions

File tree

src/common/setting-definition.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export interface RewardSettings {
210210
enableRewards: boolean;
211211
rewardItems: RewardItem[];
212212
occurrenceLevels: OccurrenceLevel[];
213+
showRewardType: "modal" | "notice"; // Type of reward display - modal (default) or notice
213214
}
214215

215216
export interface HabitSettings {
@@ -616,6 +617,7 @@ export const DEFAULT_SETTINGS: TaskProgressBarSettings = {
616617
{ name: t("rare"), chance: 25 },
617618
{ name: t("legendary"), chance: 5 },
618619
],
620+
showRewardType: "modal",
619621
},
620622

621623
// Habit Settings

src/components/habit/habit.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export class Habit extends Component {
6363

6464
getHabitData(): HabitProps[] {
6565
const habits = this.plugin.habitManager?.habits || [];
66-
console.log("habits", habits);
6766
return habits;
6867
}
6968

src/editor-ext/monitorTaskCompleted.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function monitorTaskCompletedExtension(
1313
app: App,
1414
plugin: TaskProgressBarPlugin
1515
) {
16+
console.log("monitorTaskCompletedExtension");
1617
return EditorState.transactionFilter.of((tr) => {
1718
// Handle the transaction to check for task completions
1819
handleMonitorTaskCompletionTransaction(tr, app, plugin);
@@ -32,6 +33,7 @@ function handleMonitorTaskCompletionTransaction(
3233
app: App,
3334
plugin: TaskProgressBarPlugin
3435
) {
36+
console.log("handleMonitorTaskCompletionTransaction");
3537
// Only process transactions that change the document
3638
if (!tr.docChanged) {
3739
return;
@@ -99,9 +101,11 @@ function handleMonitorTaskCompletionTransaction(
99101
newLine.number, // line numbers are 1-based
100102
plugin.settings.preferMetadataFormat // Use plugin setting for format preference
101103
);
104+
console.log(task);
102105

103106
// Optionally, trigger a custom event that other parts of the plugin or Obsidian could listen to
104107
if (task) {
108+
console.log("trigger task-completed event");
105109
app.workspace.trigger(
106110
"task-genius:task-completed",
107111
task

src/pages/TaskSpecificView.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { CalendarComponent, CalendarEvent } from "../components/calendar";
3636
import { KanbanComponent } from "../components/kanban/kanban";
3737
import { GanttComponent } from "../components/gantt/gantt";
3838
import { TaskPropertyTwoColumnView } from "../components/task-view/TaskPropertyTwoColumnView";
39+
import { Habit as HabitsComponent } from "../components/habit/habit";
3940

4041
export const TASK_SPECIFIC_VIEW_TYPE = "task-genius-specific-view";
4142

@@ -58,6 +59,7 @@ export class TaskSpecificView extends ItemView {
5859
private calendarComponent: CalendarComponent;
5960
private kanbanComponent: KanbanComponent;
6061
private ganttComponent: GanttComponent;
62+
private habitsComponent: HabitsComponent;
6163
// Custom view components by view ID
6264
private twoColumnViewComponents: Map<string, TaskPropertyTwoColumnView> =
6365
new Map();
@@ -377,6 +379,12 @@ export class TaskSpecificView extends ItemView {
377379
this.addChild(this.ganttComponent);
378380
this.ganttComponent.containerEl.hide();
379381

382+
this.habitsComponent = new HabitsComponent(
383+
this.plugin,
384+
this.rootContainerEl
385+
);
386+
this.addChild(this.habitsComponent);
387+
this.habitsComponent.containerEl.hide();
380388
this.detailsComponent = new TaskDetailsComponent(
381389
this.rootContainerEl,
382390
this.app,
@@ -486,7 +494,7 @@ export class TaskSpecificView extends ItemView {
486494
this.calendarComponent.containerEl.hide();
487495
this.kanbanComponent.containerEl.hide();
488496
this.ganttComponent.containerEl.hide();
489-
497+
this.habitsComponent.containerEl.hide();
490498
let targetComponent: any = null;
491499
let modeForComponent: ViewMode = viewId;
492500

@@ -529,6 +537,9 @@ export class TaskSpecificView extends ItemView {
529537
} else {
530538
// Standard view types
531539
switch (viewId) {
540+
case "habit":
541+
targetComponent = this.habitsComponent;
542+
break;
532543
case "forecast":
533544
targetComponent = this.forecastComponent;
534545
break;

src/setting.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,7 +2959,7 @@ export class TaskProgressBarSettingTab extends PluginSettingTab {
29592959

29602960
// --- Enable Rewards ---
29612961
new Setting(containerEl)
2962-
.setName(t("Enable Rewards"))
2962+
.setName(t("Enable rewards"))
29632963
.setDesc(t("Toggle to enable or disable the reward system."))
29642964
.addToggle((toggle) =>
29652965
toggle
@@ -2975,9 +2975,26 @@ export class TaskProgressBarSettingTab extends PluginSettingTab {
29752975
return; // Don't render the rest if rewards are disabled
29762976
}
29772977

2978+
// --- Reward Display Type ---
2979+
new Setting(containerEl)
2980+
.setName(t("Reward display type"))
2981+
.setDesc(t("Choose how rewards are displayed when earned."))
2982+
.addDropdown((dropdown) => {
2983+
dropdown
2984+
.addOption("modal", t("Modal dialog"))
2985+
.addOption("notice", t("Notice (Auto-accept)"))
2986+
.setValue(
2987+
this.plugin.settings.rewards.showRewardType || "modal"
2988+
)
2989+
.onChange(async (value: "modal" | "notice") => {
2990+
this.plugin.settings.rewards.showRewardType = value;
2991+
this.applySettingsUpdate();
2992+
});
2993+
});
2994+
29782995
// --- Occurrence Levels ---
29792996
new Setting(containerEl)
2980-
.setName(t("Occurrence Levels"))
2997+
.setName(t("Occurrence levels"))
29812998
.setDesc(
29822999
t(
29833000
"Define different levels of reward rarity and their probability."
@@ -3059,7 +3076,7 @@ export class TaskProgressBarSettingTab extends PluginSettingTab {
30593076

30603077
new Setting(occurrenceLevelsContainer).addButton((button) =>
30613078
button
3062-
.setButtonText(t("Add Occurrence Level"))
3079+
.setButtonText(t("Add occurrence level"))
30633080
.setCta()
30643081
.onClick(() => {
30653082
const newLevel: OccurrenceLevel = {
@@ -3076,7 +3093,7 @@ export class TaskProgressBarSettingTab extends PluginSettingTab {
30763093

30773094
// --- Reward Items ---
30783095
new Setting(containerEl)
3079-
.setName(t("Reward Items"))
3096+
.setName(t("Reward items"))
30803097
.setDesc(t("Manage the specific rewards that can be obtained."))
30813098
.setHeading();
30823099

@@ -3146,7 +3163,7 @@ export class TaskProgressBarSettingTab extends PluginSettingTab {
31463163
})
31473164
)
31483165
.addText((text) => {
3149-
text.setPlaceholder(t("Image URL (optional)")) // For Image URL
3166+
text.setPlaceholder(t("Image url (optional)")) // For Image URL
31503167
.setValue(item.imageUrl || "")
31513168
.onChange((value) => {
31523169
this.plugin.settings.rewards.rewardItems[
@@ -3160,7 +3177,7 @@ export class TaskProgressBarSettingTab extends PluginSettingTab {
31603177
.addButton((button) =>
31613178
button
31623179
.setIcon("trash")
3163-
.setTooltip(t("Delete Reward Item"))
3180+
.setTooltip(t("Delete reward item"))
31643181
.setClass("mod-warning")
31653182
.onClick(() => {
31663183
this.plugin.settings.rewards.rewardItems.splice(
@@ -3186,7 +3203,7 @@ export class TaskProgressBarSettingTab extends PluginSettingTab {
31863203

31873204
new Setting(rewardItemsContainer).addButton((button) =>
31883205
button
3189-
.setButtonText(t("Add Reward Item"))
3206+
.setButtonText(t("Add reward item"))
31903207
.setCta()
31913208
.onClick(() => {
31923209
const newItem: RewardItem = {

0 commit comments

Comments
 (0)