Skip to content

Commit

Permalink
Clear ext for ref
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Jan 19, 2025
1 parent 4ecd28f commit 5dfa99f
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/app/component/blog/blog-entry/blog-entry.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/component/chat/chat-entry/chat-entry.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions src/app/component/comment/comment.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@
<div class="actions">
<a [routerLink]="['/ref', ref.url, 'comments']"
[queryParams]="{ origin: nonLocalOrigin }"
(click)="store.view.setRef(ref)"
(click)="store.view.preloadRef(ref)"
i18n>permalink</a>
<a class="fake-link"
(click)="replying = !replying"
i18n>reply</a>
@if(responses) {
<a [routerLink]="['/ref', ref.url, 'responses']"
[queryParams]="{ origin: nonLocalOrigin }"
(click)="store.view.setRef(ref)"
(click)="store.view.preloadRef(ref)"
i18n>{responses, plural, =1 {1&thinsp;citation} other {{{ responses }}&thinsp;citations}}</a>
}
@if (sources > 2) {
<a [routerLink]="['/ref', ref.url, 'sources']"
[queryParams]="{ origin: nonLocalOrigin }"
(click)="store.view.setRef(ref)"
(click)="store.view.preloadRef(ref)"
i18n>{{ sources }}&thinsp;sources</a>
}
@if (writeAccess) {
Expand Down Expand Up @@ -186,7 +186,7 @@
<a class="load-more"
[routerLink]="['/ref', ref.url, 'comments']"
[queryParams]="{ origin: nonLocalOrigin }"
(click)="store.view.setRef(ref)" i18n>
(click)="store.view.preloadRef(ref)" i18n>
continue this thread
</a>
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/component/folder/file/file.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/component/notebook/note/note.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/component/ref/ref.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/page/ref/ref.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ <h5 class="print-inline" i18n>Versions</h5>
[expanded]="false"
(copied)="reload()"></app-ref>
@if (thread && store.view.current === 'ref/thread') {
<span class="parent-link fake-link print-hide" [routerLink]="['/ref', store.view.top.url, 'thread']" (click)="store.view.setRef(store.view.top)" i18n>full thread</span>
<span class="parent-link fake-link print-hide" [routerLink]="['/ref', store.view.top.url, 'thread']" (click)="store.view.preloadRef(store.view.top)" i18n>full thread</span>
} @else if (comment && store.view.current === 'ref/comments') {
<span class="parent-link fake-link print-hide" [routerLink]="['/ref', store.view.top.url, 'comments']" (click)="store.view.setRef(store.view.top)" i18n>full comments</span>
<span class="parent-link fake-link print-hide" [routerLink]="['/ref', store.view.top.url, 'comments']" (click)="store.view.preloadRef(store.view.top)" i18n>full comments</span>
} @else {
<span class="parent-link fake-link print-hide" [routerLink]="['/ref', store.view.top.url]" (click)="store.view.setRef(store.view.top)" i18n>parent</span>
<span class="parent-link fake-link print-hide" [routerLink]="['/ref', store.view.top.url]" (click)="store.view.preloadRef(store.view.top)" i18n>parent</span>
}
}
<app-ref class="full-page"
Expand Down
15 changes: 7 additions & 8 deletions src/app/page/ref/ref.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class RefPage implements OnInit, OnDestroy, HasChanges {
this.destroy$.complete();
for (const dispose of this.disposers) dispose();
this.disposers.length = 0;
this.store.view.setRef(undefined);
this.store.view.clearRef();
}

@memo
Expand Down Expand Up @@ -132,7 +132,6 @@ export class RefPage implements OnInit, OnDestroy, HasChanges {
}
if (url !== this.store.view.ref?.url) {
this.newResponses = 0;
this.store.view.clearRef();
this.refs.count({ url, obsolete: true })
.subscribe(count => runInAction(() => this.store.view.versions = count));
}
Expand All @@ -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();
Expand Down
27 changes: 13 additions & 14 deletions src/app/store/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 5dfa99f

Please sign in to comment.