Skip to content

Commit 68ae7c9

Browse files
committed
feat(client): try a different approach to handling read-only threshold
1 parent 7ba504f commit 68ae7c9

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

apps/client/src/components/note_context.ts

+24-5
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,33 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded">
261261
return true;
262262
}
263263

264-
const blob = await this.note.getBlob();
265-
if (!blob) {
266-
return false;
264+
// Store the initial decision about read-only status in the viewScope
265+
// This will be "remembered" until the viewScope is refreshed
266+
if (!this.viewScope) {
267+
this.resetViewScope();
267268
}
268269

269-
const sizeLimit = this.note.type === "text" ? options.getInt("autoReadonlySizeText") : options.getInt("autoReadonlySizeCode");
270+
// We've ensured viewScope exists by calling resetViewScope() if needed
271+
const viewScope = this.viewScope as ViewScope;
272+
273+
if (viewScope.readOnlyDecision === undefined) {
274+
const blob = await this.note.getBlob();
275+
if (!blob) {
276+
viewScope.readOnlyDecision = false;
277+
return false;
278+
}
279+
280+
const sizeLimit = this.note.type === "text"
281+
? options.getInt("autoReadonlySizeText")
282+
: options.getInt("autoReadonlySizeCode");
283+
284+
viewScope.readOnlyDecision = Boolean(sizeLimit &&
285+
blob.contentLength > sizeLimit &&
286+
!this.note.isLabelTruthy("autoReadOnlyDisabled"));
287+
}
270288

271-
return sizeLimit && blob.contentLength > sizeLimit && !this.note.isLabelTruthy("autoReadOnlyDisabled");
289+
// Return the cached decision, which won't change until viewScope is reset
290+
return viewScope.readOnlyDecision || false;
272291
}
273292

274293
async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {

apps/client/src/services/link.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface ViewScope {
4848
viewMode?: ViewMode;
4949
attachmentId?: string;
5050
readOnlyTemporarilyDisabled?: boolean;
51+
readOnlyDecision?: boolean;
5152
highlightsListPreviousVisible?: boolean;
5253
highlightsListTemporarilyHidden?: boolean;
5354
tocTemporarilyHidden?: boolean;

0 commit comments

Comments
 (0)