Skip to content

Commit

Permalink
Merge pull request #108 from liamcain/use-calendar-ui-package
Browse files Browse the repository at this point in the history
Use calendar UI package
  • Loading branch information
liamcain authored Jan 18, 2021
2 parents ffb4401 + d8bd5a4 commit 7cb658c
Show file tree
Hide file tree
Showing 29 changed files with 996 additions and 1,292 deletions.
41 changes: 41 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: Bug report
about: Create a report to help us improve
title: ""
labels: bug, needs-review
assignees: ""
---

> **Before Submitting:** Double-check that you are running the latest version of the plugin. The bug might have already been fixed 😄
### Describe the bug

_A clear and concise description of what the bug is._

### Steps to reproduce

1. Go to '...'
2. Click on '....'
3. See error

### Expected behavior

_A clear and concise description of what you expected to happen_.

### Screenshots

_If applicable, add screenshots to help explain your problem._

### Environment (please specify)

#### OS

[e.g. macOS]

#### Obsidian Version (e.g. v0.10.6)

`(Settings → About → Current Version)`

### Additional context

_Add any other context about the problem here._
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Feature request
about: Suggest an idea for this project
title: ""
labels: enhancement
assignees: ""
---

> **Before Submitting:** Double-check that you are running the latest version of the plugin. The feature might have already been included 😄
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
File renamed without changes.
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CI
on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
- name: Run tests
run: yarn test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
dist/
data.json
main.js
.vscode/
*.code-workspace
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"svelteSortOrder": "scripts-markup-styles",
"svelteBracketNewLine": true,
"svelteAllowShorthand": true,
"svelteIndentScriptAndStyle": true
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ From the Settings menu, you can toggle "Start week on Monday".

### How do I include "unformatted" words in my weekly note filenames?

If you want the weekly note format to include a word (e.g. "Week 21 of Year 2020") you can do so by surrounding the words with `[]` brackets. This tells [moment](https://momentjs.com/docs/#/displaying/format/) to ignore the words. So for the example above, you would set your format to `[Week] ww [of Year] YYYY`.
If you want the weekly note format to include a word (e.g. "Week 21 of Year 2020") you can do so by surrounding the words with `[]` brackets. This tells [moment](https://momentjs.com/docs/#/displaying/format/) to ignore the words. So for the example above, you would set your format to `[Week] ww [of Year] gggg`.

### I don't like showing the week numbers but I still want to use weekly notes. Can I still use them?

Expand Down Expand Up @@ -171,9 +171,9 @@ You can open **weekly notes** in 2 ways: searching `Calendar: open weekly note`

| Tag | Description |
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `sunday`, `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday` | Because weekly tags refer to main days, you can refer to individual days like this `{{sunday:YYYY-MM-DD}}` to automatically insert the date for that particular day. Note, you must specify the date format! |
| `sunday`, `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday` | Because weekly tags refer to main days, you can refer to individual days like this `{{sunday:gggg-MM-DD}}` to automatically insert the date for that particular day. Note, you must specify the date format! |
| `title` | Works the same as the daily note `{{title}}`. It will insert the title of the note |
| `date`, `time` | Works the same as the daily note `{{date}}` and `{{time}}`. It will insert the date and time of the first day of the week. Useful for creating a heading (e.g. `# # {{date:YYYY [Week] ww}}`). |
| `date`, `time` | Works the same as the daily note `{{date}}` and `{{time}}`. It will insert the date and time of the first day of the week. Useful for creating a heading (e.g. `# # {{date:gggg [Week] ww}}`). |

## Say Thanks 🙏

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "calendar",
"name": "Calendar",
"description": "Calendar view of your daily notes",
"version": "1.4.12",
"version": "1.4.13",
"author": "Liam Cain",
"authorUrl": "https://github.com/liamcain/",
"isDesktopOnly": false,
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "calendar",
"version": "1.4.12",
"version": "1.4.13",
"description": "Calendar view of your daily notes",
"author": "liamcain",
"main": "main.js",
Expand All @@ -13,23 +13,24 @@
},
"dependencies": {
"obsidian": "obsidianmd/obsidian-api#master",
"obsidian-daily-notes-interface": "0.3.1",
"obsidian-calendar-ui": "0.2.1",
"obsidian-daily-notes-interface": "0.5.1",
"svelte": "3.31.0",
"tslib": "2.0.3"
},
"devDependencies": {
"@rollup/plugin-commonjs": "17.0.0",
"@rollup/plugin-node-resolve": "11.0.0",
"@rollup/plugin-typescript": "8.0.0",
"@testing-library/jest-dom": "5.11.6",
"@testing-library/svelte": "3.0.0",
"@rollup/plugin-typescript": "8.1.0",
"@testing-library/jest-dom": "5.11.9",
"@testing-library/svelte": "3.0.3",
"@tsconfig/svelte": "1.0.10",
"@types/jest": "26.0.19",
"@types/jest": "26.0.20",
"@types/moment": "2.13.0",
"@types/node": "14.14.13",
"@typescript-eslint/eslint-plugin": "4.9.1",
"@typescript-eslint/parser": "4.9.1",
"eslint": "7.15.0",
"@types/node": "14.14.21",
"@typescript-eslint/eslint-plugin": "4.13.0",
"@typescript-eslint/parser": "4.13.0",
"eslint": "7.18.0",
"jest": "26.6.3",
"moment": "2.29.1",
"rollup": "2.34.2",
Expand Down
32 changes: 20 additions & 12 deletions src/io/__tests__/weeklyNotes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,31 @@ describe("getDayOfWeekNumericalValue", () => {
});

describe("start week on Sunday", () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(<any>moment.localeData())._week.dow = 0;
});

test("returns 0 for sunday", () => {
getDefaultSettings({
weekStart: "sunday",
});
expect(weeklyNote.getDayOfWeekNumericalValue("sunday")).toEqual(0);
});

test("returns 1 for monday", () => {
getDefaultSettings({
weekStart: "sunday",
});
expect(weeklyNote.getDayOfWeekNumericalValue("monday")).toEqual(1);
});
});

describe("start week on Monday", () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(<any>moment.localeData())._week.dow = 1;
});

test("returns 0 for sunday", () => {
getDefaultSettings({
weekStart: "monday",
});
expect(weeklyNote.getDayOfWeekNumericalValue("sunday")).toEqual(6);
});

test("returns 1 for monday", () => {
getDefaultSettings({
weekStart: "monday",
});
expect(weeklyNote.getDayOfWeekNumericalValue("monday")).toEqual(0);
});
});
Expand Down Expand Up @@ -85,6 +83,11 @@ describe("createWeeklyNote", () => {
});

describe("start week on Sunday", () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(<any>moment.localeData())._week.dow = 0;
});

test("replaces {{sunday}} and {{monday}} in weekly note", async () => {
(getTemplateContents as jest.MockedFunction<
typeof getTemplateContents
Expand All @@ -105,6 +108,11 @@ describe("createWeeklyNote", () => {
});

describe("start week on Monday", () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(<any>moment.localeData())._week.dow = 1;
});

test("replaces {{sunday}} and {{monday}} in weekly note", async () => {
(getTemplateContents as jest.MockedFunction<
typeof getTemplateContents
Expand Down
2 changes: 1 addition & 1 deletion src/io/weeklyNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function tryToCreateWeeklyNote(
cta: "Create",
onAccept: createFile,
text: `File ${filename} does not exist. Would you like to create it?`,
title: "New Daily Note",
title: "New Weekly Note",
});
} else {
await createFile();
Expand Down
46 changes: 0 additions & 46 deletions src/localization.ts

This file was deleted.

45 changes: 10 additions & 35 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import type { Moment, WeekSpec } from "moment";
import { App, Plugin, WorkspaceLeaf } from "obsidian";

import { configureMomentLocale } from "src/localization";

import { VIEW_TYPE_CALENDAR } from "./constants";
import { getWeeklyNote } from "./io/weeklyNotes";
import {
CalendarSettingsTab,
SettingsInstance,
ISettings,
syncMomentLocaleWithSettings,
} from "./settings";
import { settings } from "./ui/stores";
import { CalendarSettingsTab, ISettings } from "./settings";
import CalendarView from "./view";

declare global {
Expand All @@ -33,16 +26,14 @@ export default class CalendarPlugin extends Plugin {

async onload(): Promise<void> {
this.register(
SettingsInstance.subscribe((value) => {
settings.subscribe((value) => {
this.options = value;
configureMomentLocale(this.options);
})
);

this.registerView(
VIEW_TYPE_CALENDAR,
(leaf: WorkspaceLeaf) =>
(this.view = new CalendarView(leaf, this.options))
(leaf: WorkspaceLeaf) => (this.view = new CalendarView(leaf))
);

this.addCommand({
Expand All @@ -61,17 +52,7 @@ export default class CalendarPlugin extends Plugin {
this.addCommand({
id: "open-weekly-note",
name: "Open Weekly Note",
callback: () => {
const date = window.moment();
const existingFile = getWeeklyNote(date, this.options);
this.view.openOrCreateWeeklyNote(date, existingFile, false);
},
});

this.addCommand({
id: "reload-calendar-view",
name: "Reload daily note settings",
callback: () => this.view.redraw(),
callback: () => this.view.openOrCreateWeeklyNote(window.moment(), false),
});

this.addCommand({
Expand All @@ -82,10 +63,6 @@ export default class CalendarPlugin extends Plugin {

await this.loadOptions();

// After we retrieve the settings, override window.moment to
// reflect 'start week on monday' setting
syncMomentLocaleWithSettings(this.options);

this.addSettingTab(new CalendarSettingsTab(this.app, this));

if (this.app.workspace.layoutReady) {
Expand All @@ -108,7 +85,7 @@ export default class CalendarPlugin extends Plugin {

async loadOptions(): Promise<void> {
const options = await this.loadData();
SettingsInstance.update((old) => {
settings.update((old) => {
return {
...old,
...(options || {}),
Expand All @@ -118,12 +95,10 @@ export default class CalendarPlugin extends Plugin {
await this.saveData(this.options);
}

async writeOptions(changeOpts: (settings: ISettings) => void): Promise<void> {
SettingsInstance.update((old) => {
changeOpts(old);
return old;
});
syncMomentLocaleWithSettings(this.options);
async writeOptions(
changeOpts: (settings: ISettings) => Partial<ISettings>
): Promise<void> {
settings.update((old) => ({ ...old, ...changeOpts(old) }));
await this.saveData(this.options);
}
}
Loading

0 comments on commit 7cb658c

Please sign in to comment.