Skip to content

Commit

Permalink
Fix #1475 again
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomas2 committed Aug 12, 2021
1 parent e665d1b commit 208d85c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 2 additions & 4 deletions app/bibleview-js/src/components/modals/InputText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import Modal from "@/components/modals/Modal";
import {ref} from "@vue/reactivity";
import {useCommon} from "@/composables";
import {Deferred} from "@/utils";
import {nextTick} from "@vue/runtime-core";
import {Deferred, waitUntilRefValue} from "@/utils";
export default {
name: "InputText",
components: {Modal},
Expand All @@ -54,8 +53,7 @@ export default {
error.value = _error;
show.value = true;
promise = new Deferred();
await nextTick();
await nextTick();
await waitUntilRefValue(inputElement)
inputElement.value.focus();
const result = await promise.wait()
show.value = false;
Expand Down
17 changes: 16 additions & 1 deletion app/bibleview-js/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* If not, see http://www.gnu.org/licenses/.
*/

import {onBeforeUnmount, onMounted, onUnmounted} from "@vue/runtime-core";
import {onBeforeUnmount, onMounted, onUnmounted, watch} from "@vue/runtime-core";
import Color from "color";
import {rybColorMixer} from "@/lib/ryb-color-mixer";
import {get, sortBy} from "lodash";
Expand Down Expand Up @@ -494,3 +494,18 @@ export function createDoubleClickDetector(waitMs = 300) {
export function isBottomHalfClicked(event) {
return event.clientY > (window.innerHeight / 2);
}

export async function waitUntilRefValue(ref_) {
return await new Promise(resolve => {
if (ref_.value) {
resolve(ref_.value);
return;
}
const stop = watch(ref_, newValue => {
if (newValue) {
stop();
resolve(newValue);
}
});
});
}

0 comments on commit 208d85c

Please sign in to comment.