From 5dfa99fdb9f4ee72fe0be80c42e75476963322d8 Mon Sep 17 00:00:00 2001 From: Chris Malloy Date: Sun, 19 Jan 2025 03:14:24 -0400 Subject: [PATCH] Clear ext for ref --- .../blog/blog-entry/blog-entry.component.ts | 2 +- .../chat/chat-entry/chat-entry.component.ts | 2 +- .../component/comment/comment.component.html | 8 +++--- .../component/folder/file/file.component.ts | 2 +- .../kanban-card/kanban-card.component.ts | 2 +- .../component/notebook/note/note.component.ts | 2 +- src/app/component/ref/ref.component.ts | 2 +- src/app/page/ref/ref.component.html | 6 ++--- src/app/page/ref/ref.component.ts | 15 +++++------ src/app/store/view.ts | 27 +++++++++---------- 10 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/app/component/blog/blog-entry/blog-entry.component.ts b/src/app/component/blog/blog-entry/blog-entry.component.ts index b949a02a..d61cc547 100644 --- a/src/app/component/blog/blog-entry/blog-entry.component.ts +++ b/src/app/component/blog/blog-entry/blog-entry.component.ts @@ -316,7 +316,7 @@ export class BlogEntryComponent implements OnChanges, OnDestroy, HasChanges { } saveRef() { - this.store.view.setRef(this.ref, this.repostRef); + this.store.view.preloadRef(this.ref, this.repostRef); } download() { diff --git a/src/app/component/chat/chat-entry/chat-entry.component.ts b/src/app/component/chat/chat-entry/chat-entry.component.ts index 7f7c3003..655bdda2 100644 --- a/src/app/component/chat/chat-entry/chat-entry.component.ts +++ b/src/app/component/chat/chat-entry/chat-entry.component.ts @@ -253,7 +253,7 @@ export class ChatEntryComponent implements OnChanges { } saveRef() { - this.store.view.setRef(this.ref, this.repostRef); + this.store.view.preloadRef(this.ref, this.repostRef); } tag$ = (tag: string) => { diff --git a/src/app/component/comment/comment.component.html b/src/app/component/comment/comment.component.html index 88890c57..23efa179 100644 --- a/src/app/component/comment/comment.component.html +++ b/src/app/component/comment/comment.component.html @@ -118,7 +118,7 @@
permalink {responses, plural, =1 {1 citation} other {{{ responses }} citations}} } @if (sources > 2) { {{ sources }} sources } @if (writeAccess) { @@ -186,7 +186,7 @@ + (click)="store.view.preloadRef(ref)" i18n> continue this thread } diff --git a/src/app/component/folder/file/file.component.ts b/src/app/component/folder/file/file.component.ts index 755e45da..516a2bb5 100644 --- a/src/app/component/folder/file/file.component.ts +++ b/src/app/component/folder/file/file.component.ts @@ -174,7 +174,7 @@ export class FileComponent implements OnChanges { } saveRef() { - this.store.view.setRef(this.ref, this.repostRef); + this.store.view.preloadRef(this.ref, this.repostRef); } showIcon(i: Icon) { diff --git a/src/app/component/kanban/kanban-card/kanban-card.component.ts b/src/app/component/kanban/kanban-card/kanban-card.component.ts index 909f77e3..52625dcc 100644 --- a/src/app/component/kanban/kanban-card/kanban-card.component.ts +++ b/src/app/component/kanban/kanban-card/kanban-card.component.ts @@ -297,7 +297,7 @@ export class KanbanCardComponent implements OnChanges, AfterViewInit { } saveRef() { - this.store.view.setRef(this.ref, this.repostRef); + this.store.view.preloadRef(this.ref, this.repostRef); } close() { diff --git a/src/app/component/notebook/note/note.component.ts b/src/app/component/notebook/note/note.component.ts index 1c83eb41..8eac9435 100644 --- a/src/app/component/notebook/note/note.component.ts +++ b/src/app/component/notebook/note/note.component.ts @@ -297,7 +297,7 @@ export class NoteComponent implements OnChanges, AfterViewInit { } saveRef() { - this.store.view.setRef(this.ref, this.repostRef); + this.store.view.preloadRef(this.ref, this.repostRef); } close() { diff --git a/src/app/component/ref/ref.component.ts b/src/app/component/ref/ref.component.ts index fbf2760e..51656a3a 100644 --- a/src/app/component/ref/ref.component.ts +++ b/src/app/component/ref/ref.component.ts @@ -823,7 +823,7 @@ export class RefComponent implements OnChanges, AfterViewInit, OnDestroy, HasCha } saveRef() { - this.store.view.setRef(this.ref, this.repostRef); + this.store.view.preloadRef(this.ref, this.repostRef); } formatAuthor(user: string) { diff --git a/src/app/page/ref/ref.component.html b/src/app/page/ref/ref.component.html index 9dda63ed..b4f66d54 100644 --- a/src/app/page/ref/ref.component.html +++ b/src/app/page/ref/ref.component.html @@ -81,11 +81,11 @@ [expanded]="false" (copied)="reload()"> @if (thread && store.view.current === 'ref/thread') { - full thread + full thread } @else if (comment && store.view.current === 'ref/comments') { - full comments + full comments } @else { - parent + parent } } runInAction(() => this.store.view.versions = count)); } @@ -142,14 +141,14 @@ export class RefPage implements OnInit, OnDestroy, HasChanges { ).pipe( catchError(err => err.status === 404 ? of(undefined) : throwError(() => err)), map(ref => ref || { url }), - tap(ref => this.store.view.setRef(ref)), - switchMap(ref => (!this.comment && !this.thread) ? of(undefined) - : top(ref) === url ? of(ref) - : top(ref) === this.store.view.top?.url ? of(this.store.view.top) + switchMap(ref => (!this.comment && !this.thread) ? of([ref, undefined]) + : top(ref) === url ? of([ref, ref]) + : top(ref) === this.store.view.top?.url ? of([ref, this.store.view.top]) : this.refs.getCurrent(top(ref)).pipe( - catchError(err => err.status === 404 ? of(undefined) : throwError(() => err)), + catchError(err => err.status === 404 ? of([ref, undefined]) : throwError(() => err)), + map(top => [ref, top] as [Ref, Ref]), )), - tap(top => runInAction(() => this.store.view.top = top)), + tap(([ref, top]) => runInAction(() => this.store.view.clearRef(ref, top))), ).subscribe(); if (this.config.websockets) { this.watchSelf?.unsubscribe(); diff --git a/src/app/store/view.ts b/src/app/store/view.ts index 63949e4a..ea1c000e 100644 --- a/src/app/store/view.ts +++ b/src/app/store/view.ts @@ -12,7 +12,6 @@ import { getPageTitle } from '../util/format'; import { UrlFilter } from '../util/query'; import { hasPrefix, hasTag, isQuery, localTag, queryPrefix, topAnds } from '../util/tag'; import { AccountStore } from './account'; -import { EventBus } from './bus'; /** * ID for current view. Only includes pages that make queries. @@ -51,11 +50,11 @@ export class ViewStore { constructor( public route: RouterStore, private account: AccountStore, - private eventBus: EventBus, ) { makeAutoObservable(this, { clear: action, - setRef: action, + clearRef: action, + preloadRef: action, setLastSelected: action, exts: observable.shallow, extTemplates: observable.shallow, @@ -65,14 +64,6 @@ export class ViewStore { this.clear(); // Initial observables may not be null for MobX } - setRef(ref?: Ref, top?: Ref) { - if (this.ref && this.ref !== ref) { - this.lastSelected = this.ref; - } - this.ref = ref; - if (top) this.top = top; - } - setLastSelected(ref?: Ref) { this.lastSelected = ref; } @@ -92,15 +83,23 @@ export class ViewStore { this.defaultSearchSort = defaultSearchSort; } - clearRef(defaultSort: RefSort[] | TagSort[] = ['published'], defaultSearchSort: RefSort[] | TagSort[] = ['rank']) { - this.ref = undefined; - this.top = undefined; + clearRef(ref?: Ref, top?: Ref, defaultSort: RefSort[] | TagSort[] = ['published'], defaultSearchSort: RefSort[] | TagSort[] = ['rank']) { + this.ref = ref; + if (ref) this.lastSelected = ref; + this.top = top; this.versions = 0; + this.exts = []; + this.extTemplates = []; this.selectedUser = undefined; this.defaultSort = defaultSort; this.defaultSearchSort = defaultSearchSort; } + preloadRef(ref: Ref, top?: Ref) { + this.ref = ref; + this.top = top; + } + get pageTitle() { return getPageTitle(this.ref, this.top); }