diff --git a/docs/releases/v2.12.2.md b/docs/releases/v2.12.2.md index 92ec10a5c2fd00018a2f316e416f9ad7aa11baa5..8043ff60944528957119ef01c3299f31e352be08 100644 --- a/docs/releases/v2.12.2.md +++ b/docs/releases/v2.12.2.md @@ -4,4 +4,4 @@ - fixes screenshot in fsaverage - on hover region label in fsaverage now display properly -- fixes annotation mode (export annotations) +- fixes annotation mode (export annotations, annotations fail to render in viewer on startup (via shared link, local storage etc)) diff --git a/src/atlasComponents/annotations/annotation.service.ts b/src/atlasComponents/annotations/annotation.service.ts index 543271a3a11ac766c9f194152d06b3c497a26a4f..d133671c3682ccf16c5af36271a12b90fbb4cf73 100644 --- a/src/atlasComponents/annotations/annotation.service.ts +++ b/src/atlasComponents/annotations/annotation.service.ts @@ -1,6 +1,6 @@ import { BehaviorSubject, Observable } from "rxjs"; import { distinctUntilChanged } from "rxjs/operators"; -import { getUuid } from "src/util/fn"; +import { getUuid, waitFor } from "src/util/fn"; import { PeriodicSvc } from "src/util/periodic.service"; export type TNgAnnotationEv = { @@ -144,8 +144,8 @@ export class AnnotationLayer { return false }) } - removeAnnotation(spec: { id: string }) { - if (!this.nglayer) return + async removeAnnotation(spec: { id: string }) { + await waitFor(() => !!this.nglayer?.layer?.localAnnotations) const { localAnnotations } = this.nglayer.layer this.idset.delete(spec.id) const ref = localAnnotations.references.get(spec.id) @@ -155,8 +155,8 @@ export class AnnotationLayer { } } async updateAnnotation(spec: AnnotationSpec) { - const localAnnotations = this.nglayer?.layer?.localAnnotations - if (!localAnnotations) return + await waitFor(() => !!this.nglayer?.layer?.localAnnotations) + const { localAnnotations } = this.nglayer.layer const ref = localAnnotations.references.get(spec.id) const _spec = this.parseNgSpecType(spec) if (ref) { diff --git a/src/atlasComponents/userAnnotations/tools/service.ts b/src/atlasComponents/userAnnotations/tools/service.ts index 847abe0c24f9496cd16b08bb949991b96ebf4041..9ef8d363ac2a1201e28854b1b940d44967f5def6 100644 --- a/src/atlasComponents/userAnnotations/tools/service.ts +++ b/src/atlasComponents/userAnnotations/tools/service.ts @@ -410,13 +410,9 @@ export class ModularUserAnnotationToolService implements OnDestroy{ })), ) ]).pipe( - map(([_, annts]) => { - const out = [] - for (const ann of annts) { - out.push(...ann.toNgAnnotation()) - } - return out - }), + map(([_, annts]) => + annts.map(ann => ann.toNgAnnotation()).flatMap(v => v) + ), shareReplay(1), ) this.subscription.push( diff --git a/src/util/fn.ts b/src/util/fn.ts index a859bad0898788e5c06c1e8292ddf2c66cafb452..4830a09ba55222850e5753afc85cea94e761aeba 100644 --- a/src/util/fn.ts +++ b/src/util/fn.ts @@ -419,3 +419,14 @@ export function wait(ms: number){ rs(null) }, ms)) } + +/** + * @description Wait until predicate returns true. Tries once every 16 ms. + * @param predicate + */ +export async function waitFor(predicate: () => boolean) { + while (true) { + if (predicate()) break + await wait(16) + } +}