Skip to content

Commit

Permalink
v1.4.2 - debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zoreet committed Jun 6, 2024
1 parent bdaf235 commit 778acea
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "habit-tracker-21",
"name": "Habit Tracker 21",
"version": "1.4.1",
"version": "1.4.2",
"minAppVersion": "1.1.0",
"description": "Your 21-day journey to habit formation, simplified",
"author": "Zoreet",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-sample-plugin",
"version": "1.0.0",
"version": "1.4.2",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
21 changes: 19 additions & 2 deletions src/HabitTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ interface HabitTrackerSettings {
daysToLoad: number
rootElement: HTMLDivElement | undefined
habitsGoHere: HTMLDivElement | undefined
debug: number
}

const DEFAULT_SETTINGS = (): HabitTrackerSettings => ({
path: '',
path: 'Habits',
lastDisplayedDate: getTodayDate(),
daysToShow: DAYS_TO_SHOW,
daysToLoad: DAYS_TO_LOAD,
rootElement: undefined,
habitsGoHere: undefined,
debug: 0,
})

const ALLOWED_USER_SETTINGS = ['path', 'lastDisplayedDate', 'daysToShow']
const ALLOWED_USER_SETTINGS = ['path', 'lastDisplayedDate', 'daysToShow', 'debug']

function getTodayDate() {
const today = new Date()
Expand Down Expand Up @@ -88,6 +90,10 @@ export default class HabitTracker {
files.forEach(async (f) => {
this.renderHabit(f.path, await this.getHabitEntries(f.path))
})

if (this.settings.debug) {
this.renderDebugData();
}
}

loadFiles() {
Expand Down Expand Up @@ -117,6 +123,7 @@ export default class HabitTracker {
settings.daysToLoad = settings.daysToShow + 1
return settings
} catch (error) {
console.log(error);
new Notice(
`${PLUGIN_NAME}: received invalid settings. continuing with default settings`,
)
Expand All @@ -135,6 +142,13 @@ export default class HabitTracker {
return result
}

renderDebugData() {
this.settings.rootElement?.createEl('pre', {
// get the json printed with indentation
text: JSON.stringify(this.settings, null, 2),
})
}

renderNoHabitsFoundMessage() {
this.settings.rootElement?.createEl('div', {
text: `No habits found under ${this.settings.path}`,
Expand Down Expand Up @@ -177,6 +191,9 @@ export default class HabitTracker {
currentDate,
)}`,
text: day,
attr: {
'data-date': this.getDateId(currentDate),
},
})
currentDate.setDate(currentDate.getDate() + 1)
}
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export default class HabitTracker21 extends Plugin {
'habittracker',
async (src, el, ctx) => {
// track if people are using this version
const trackingPixel = document.createElement("img");
trackingPixel.src = "https://fireship-svelte-course-e89cd.web.app/api/track/habit-tracker-21/1.4.1";
trackingPixel.setAttribute("style", "height: 1px; width: 1px; border: none; opacity: 0; position: absolute; top: 0; left: 0;pointer-events: none;")
el.appendChild(trackingPixel);
const bitly = document.createElement('img');
bitly.setAttribute('src', 'https://bit.ly/habitttracker21-142');
bitly.setAttribute("style", "height: 1px; width: 1px; border: none; opacity: 0; position: absolute; top: 0; left: 0;pointer-events: none;")
el?.parentElement.appendChild(bitly);
new HabitTracker(src, el, ctx, this.app)
},
)
Expand Down
20 changes: 19 additions & 1 deletion src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,25 @@
text-align: center;
}

/* HABIT TICK */
.habit-tracker__header .habit-tracker__cell[data-date] {
position: relative;
}
.habit-tracker__header .habit-tracker__cell[data-date]:hover {
cursor: pointer;
background: var(--color-base-100);
color: var(--color-base-00);
}
.habit-tracker__header .habit-tracker__cell[data-date]:hover:after {
background: var(--color-base-100);
color: var(--color-base-00);
content: attr(data-date);
left: -34px;
padding: 2px 4px;
position: absolute;
top: 100%;
white-space: nowrap;
width: 80px;
}

.habit-tick {
line-height: 0;
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"1.2.1": "1.1.0",
"1.3.0": "1.1.0",
"1.4.0": "1.1.0",
"1.4.1": "1.1.0"
"1.4.1": "1.1.0",
"1.4.2": "1.1.0"
}

0 comments on commit 778acea

Please sign in to comment.