Skip to content

Commit 7e948d8

Browse files
committed
handle modal toggling better
1 parent 7b7f081 commit 7e948d8

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

frontend/app/typeahead/typeahead.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,8 @@ const TypeaheadInner: React.FC<Omit<TypeaheadProps, "isOpen">> = ({
170170

171171
useEffect(() => {
172172
const handleClickOutside = (event: MouseEvent) => {
173-
if (
174-
dropdownRef.current &&
175-
!dropdownRef.current.contains(event.target as Node) &&
176-
anchorRef.current &&
177-
!anchorRef.current.contains(event.target as Node)
178-
) {
173+
console.log("TYPEAHEAD handleClickOutside");
174+
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
179175
onClose();
180176
}
181177
};

frontend/app/view/preview/preview.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export class PreviewModel implements ViewModel {
163163
connectionError: PrimitiveAtom<string>;
164164

165165
openFileModal: PrimitiveAtom<boolean>;
166+
openFileModalDelay: PrimitiveAtom<boolean>;
166167
openFileError: PrimitiveAtom<string>;
167168
openFileModalGiveFocusRef: React.MutableRefObject<() => boolean>;
168169

@@ -185,6 +186,7 @@ export class PreviewModel implements ViewModel {
185186
this.refreshVersion = atom(0);
186187
this.previewTextRef = createRef();
187188
this.openFileModal = atom(false);
189+
this.openFileModalDelay = atom(false);
188190
this.openFileError = atom(null) as PrimitiveAtom<string>;
189191
this.openFileModalGiveFocusRef = createRef();
190192
this.manageConnection = atom(true);
@@ -252,7 +254,7 @@ export class PreviewModel implements ViewModel {
252254
text: headerPath,
253255
ref: this.previewTextRef,
254256
className: "preview-filename",
255-
onClick: () => this.updateOpenFileModalAndError(true),
257+
onClick: () => this.toggleOpenFileModal(),
256258
},
257259
];
258260
let saveClassName = "grey";
@@ -537,6 +539,25 @@ export class PreviewModel implements ViewModel {
537539
updateOpenFileModalAndError(isOpen, errorMsg = null) {
538540
globalStore.set(this.openFileModal, isOpen);
539541
globalStore.set(this.openFileError, errorMsg);
542+
if (isOpen) {
543+
globalStore.set(this.openFileModalDelay, true);
544+
} else {
545+
const delayVal = globalStore.get(this.openFileModalDelay);
546+
if (delayVal) {
547+
setTimeout(() => {
548+
globalStore.set(this.openFileModalDelay, false);
549+
}, 200);
550+
}
551+
}
552+
}
553+
554+
toggleOpenFileModal() {
555+
const modalOpen = globalStore.get(this.openFileModal);
556+
const delayVal = globalStore.get(this.openFileModalDelay);
557+
if (!modalOpen && delayVal) {
558+
return;
559+
}
560+
this.updateOpenFileModalAndError(!modalOpen);
540561
}
541562

542563
async goHistory(newPath: string) {
@@ -811,12 +832,9 @@ export class PreviewModel implements ViewModel {
811832
fireAndForget(() => this.goParentDirectory({}));
812833
return true;
813834
}
814-
const openModalOpen = globalStore.get(this.openFileModal);
815-
if (!openModalOpen) {
816-
if (checkKeyPressed(e, "Cmd:o")) {
817-
this.updateOpenFileModalAndError(true);
818-
return true;
819-
}
835+
if (checkKeyPressed(e, "Cmd:o")) {
836+
this.toggleOpenFileModal();
837+
return true;
820838
}
821839
const canPreview = globalStore.get(this.canPreview);
822840
if (canPreview) {
@@ -1066,7 +1084,6 @@ const SpecializedView = memo(({ parentRef, model }: SpecializedViewProps) => {
10661084
if (!SpecializedViewComponent) {
10671085
return <CenteredDiv>Invalid Specialzied View Component ({specializedView.specializedView})</CenteredDiv>;
10681086
}
1069-
console.log("RENDER AGAIN SpecializedView", model, parentRef);
10701087
return <SpecializedViewComponent model={model} parentRef={parentRef} />;
10711088
});
10721089

0 commit comments

Comments
 (0)