Skip to content

Commit

Permalink
Merge pull request #22 from dartungar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dartungar authored Dec 6, 2023
2 parents eae8297 + 597db25 commit 8adb9fc
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "mood-tracker",
"name": "Mood Tracker",
"version": "0.3.1",
"version": "0.3.2",
"minAppVersion": "1.1.0",
"description": "Track your moods & emotions easily. Visualize tracked history and browse the past entries.",
"author": "dartungar",
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
App,
Editor,
MarkdownView,
Modal,
Notice,
Plugin,
PluginSettingTab,
Setting,
} from "obsidian";
import {
DEFAULT_SETTINGS,
Expand All @@ -18,7 +12,6 @@ import { MoodTrackerService } from "./services/moodTrackerEntryService";
import { PersistenceService } from "./services/persistenceService";
import { IMoodTrackerEntry } from "./entities/MoodTrackerEntry";
import { MoodTrackerStatsModal } from "./statsModal/moodTrackerStatsModal";
import { getAverageMoodRatingByDay } from "./statsModal/statsHelpers";
import { EmotionSection } from "./entities/IEmotionSection";

import type moment from "moment";
Expand Down Expand Up @@ -83,7 +76,6 @@ export default class MoodTrackerPlugin extends Plugin {

async loadEntries() {
this.entries = (await this.persistenceService.getEntries()) ?? [];

}

async saveEntries(): Promise<void> {
Expand All @@ -95,12 +87,12 @@ export default class MoodTrackerPlugin extends Plugin {
await this.saveEntries();
}

public showNotice(message: string, durationMs: number = 5000) {
public showNotice(message: string, durationMs = 5000) {
new Notice(message, durationMs);
}

async loadSettings() {
let loadedData: MoodTrackerSettings | any = Object.assign(
const loadedData: MoodTrackerSettings | any = Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData()
Expand Down
9 changes: 3 additions & 6 deletions src/services/persistenceService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { MoodTrackerEntry } from "src/entities/MoodTrackerEntry";
import MoodTrackerPlugin from "src/main";
import fs from "fs/promises";
import type moment from "moment";



export class PersistenceService {
Expand All @@ -14,7 +11,7 @@ export class PersistenceService {
}

public async getEntries(): Promise<MoodTrackerEntry[] | undefined> {
let adapter = this.plugin.app.vault.adapter;
const adapter = this.plugin.app.vault.adapter;

await this.createDataFileIfNotExists();

Expand All @@ -37,7 +34,7 @@ export class PersistenceService {
}

public async saveEntries(): Promise<void> {
let adapter = this.plugin.app.vault.adapter;
const adapter = this.plugin.app.vault.adapter;

await this.createDataFileIfNotExists();

Expand All @@ -54,7 +51,7 @@ export class PersistenceService {
}

private async createDataFileIfNotExists(): Promise<void> {
let adapter = this.plugin.app.vault.adapter;
const adapter = this.plugin.app.vault.adapter;

if (!await adapter.exists(this.plugin.settings.folderPath)) {
this.plugin.showNotice(`Mood Tracker: folder "${this.plugin.settings.folderPath}" not found, creating it...`);
Expand Down
2 changes: 0 additions & 2 deletions src/statsModal/StatsComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
let moodRatingLabelDict: { [key: number]: string } = {};
let timer: any;
let rawData: IMoodTrackerEntry[] = this.plugin?.entries ?? [];
let processedData: IDayStats[] = [];
Expand Down Expand Up @@ -78,7 +77,6 @@
}
function subtractDays(date: Date, days: number) {
console.log("substract days", date, days);
const dateCopy = new Date(date);
dateCopy.setDate(dateCopy.getDate() - days);
Expand Down
7 changes: 5 additions & 2 deletions src/statsModal/moodTrackerStatsModal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, Modal } from "obsidian";
import StatsComponent from "./StatsComponent.svelte";
import StatsComponent from "./StatsComponent.svelte";
import store from "src/store";
import MoodTrackerPlugin from "src/main";

Expand All @@ -11,11 +11,14 @@ export class MoodTrackerStatsModal extends Modal {
super(app);
}

onOpen() {
async onOpen() {
store.plugin.set(this.plugin);

this.modalEl.addClass("mood-tracker-modal");

// reload data in case data file was synced / modified
await this.plugin.loadEntries();

this.component = new StatsComponent({
target: this.contentEl,
props: {
Expand Down
10 changes: 3 additions & 7 deletions src/statsModal/statsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { IMoodTrackerEntry } from "src/entities/MoodTrackerEntry";

export function generateDatasetForDateRange(entries: IMoodTrackerEntry[], start: Date | string, end: Date | string): IDayStats[] {
// TODO: generate data only if there are entries for the date range
console.log("generateDatasetForDateRange", start, end);
const dayStats = getAverageMoodRatingByDay(entries);
var days = generateStringDatesForDateRange(start, end);
const days = generateStringDatesForDateRange(start, end);


var dataset: IDayStats[] = days.map(day => {
var stat = dayStats.find(x => x.date == day);
const dataset: IDayStats[] = days.map(day => {
const stat = dayStats.find(x => x.date == day);

return {
date: day,
Expand Down Expand Up @@ -53,7 +52,6 @@ function generateStringDatesForDateRange(start: Date | string, end: Date | strin
const endDate = new Date(end);
const currentDate = new Date();
const endDateCorrected = endDate.getFullYear() > currentDate.getFullYear() ? currentDate : endDate;
console.log("generating string dates", startDateCorrected, endDateCorrected );

while (startDateCorrected <= endDateCorrected) {
const formattedDate = startDateCorrected.toISOString().split('T')[0];
Expand Down Expand Up @@ -89,11 +87,9 @@ export function generateStringDatesForNdays(n: number): string[] {
dates.push(dateString);
}

// print the array of dates to the console
return dates;
}

export function dateToNormalizedString(date: Date): string {
console.log("date to normalized string", date);
return date.toISOString().split('T')[0];
}

0 comments on commit 8adb9fc

Please sign in to comment.