Skip to content

Commit

Permalink
fix: cannot load daily notes after first init when reloading Obsidian
Browse files Browse the repository at this point in the history
  • Loading branch information
Quorafind committed Jul 15, 2024
1 parent fa06fc0 commit ef58377
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
18 changes: 9 additions & 9 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "daily-notes-editor",
"name": "Daily Notes Editor",
"version": "0.1.7",
"minAppVersion": "0.15.0",
"description": "Edit a bunch of daily notes in one page(inline), which works similar to Roam Research's default daily note view.",
"author": "Quorafind",
"authorUrl": "https://obsidian.md",
"isDesktopOnly": false
}
"id": "daily-notes-editor",
"name": "Daily Notes Editor",
"version": "0.1.8",
"minAppVersion": "0.15.0",
"description": "Edit a bunch of daily notes in one page(inline), which works similar to Roam Research's default daily note view.",
"author": "Quorafind",
"authorUrl": "https://obsidian.md",
"isDesktopOnly": false
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "daily-notes-editor",
"version": "0.1.7",
"version": "0.1.8",
"description": "A plugin for you to edit a bunch of daily notes in one page(inline), which works similar to Roam Research's default daily note view.",
"main": "main.js",
"scripts": {
Expand Down
33 changes: 27 additions & 6 deletions src/component/DailyNoteEditorView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
getDailyNoteSettings,
DEFAULT_DAILY_NOTE_FORMAT
} from 'obsidian-daily-notes-interface';
import { onMount } from "svelte";
export let plugin: DailyNoteViewPlugin;
export let leaf: WorkspaceLeaf;
Expand All @@ -27,6 +29,9 @@
let hasFetch = false;
let hasCurrentDay: boolean = true;
let firstLoaded = true;
let loaderRef: HTMLDivElement;
$: if (hasMore && !hasFetch) {
cacheDailyNotes = getAllDailyNotes();
// Build notes list by date in descending order.
Expand All @@ -37,6 +42,12 @@
checkDailyNote();
}
onMount(() => {
checkDailyNote();
startFillViewport();
});
function checkDailyNote() {
// @ts-ignore
const currentDate = moment();
Expand Down Expand Up @@ -79,6 +90,18 @@
...renderedDailyNotes,
...allDailyNotes.splice(0, size)
];
if (firstLoaded) {
window.setTimeout(() => {
ensureViewFilled();
firstLoaded = false;
}, 100);
}
}
}
function ensureViewFilled() {
if (loaderRef && loaderRef.getBoundingClientRect().top < leaf.view.contentEl.innerHeight) {
infiniteHandler();
}
}
Expand Down Expand Up @@ -155,13 +178,16 @@
{#each renderedDailyNotes as file (file)}
<DailyNote file={file} plugin={plugin} leaf={leaf}/>
{/each}
<div use:inview={{}} on:inview_init={startFillViewport} on:inview_change={infiniteHandler}
<div bind:this={loaderRef} class="dn-view-loader" use:inview={{
root: leaf.view.containerEl
}} on:inview_init={startFillViewport} on:inview_change={infiniteHandler}
on:inview_leave={stopFillViewport}/>
{#if !hasMore}
<div class="no-more-text">—— No more of results ——</div>
{/if}
</div>


<style>
.dn-stock {
height: 1000px;
Expand Down Expand Up @@ -196,9 +222,4 @@
margin-right: auto;
text-align: center;
}
/*.daily-note-view{*/
/* display: flex;*/
/* flex-direction: row;*/
/*}*/
</style>
4 changes: 2 additions & 2 deletions src/dailyNoteViewIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
TFile,
Workspace,
WorkspaceContainer, WorkspaceItem,
WorkspaceLeaf, TAbstractFile, Scope, Notice
WorkspaceLeaf, TAbstractFile, Scope
} from 'obsidian';
import DailyNoteEditorView from "./component/DailyNoteEditorView.svelte";
import { around } from "monkey-around";
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class DailyNoteViewPlugin extends Plugin {

this.registerView(DAILY_NOTE_VIEW_TYPE, (leaf: WorkspaceLeaf) => (this.view = new DailyNoteView(leaf, this)));

this.addRibbonIcon('daily-note', 'Open Daily Note Editor', (evt: MouseEvent) => this.openDailyNoteEditor());
this.addRibbonIcon('calendar-range', 'Open Daily Note Editor', (evt: MouseEvent) => this.openDailyNoteEditor());
this.addCommand({
id: 'open-daily-note-editor',
name: 'Open Daily Note Editor',
Expand Down
2 changes: 1 addition & 1 deletion styles.css

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

0 comments on commit ef58377

Please sign in to comment.