fixed dialog

This commit is contained in:
Jade (Rose) Rowland 2024-08-11 00:57:49 -04:00
parent d80c06cd55
commit e9a0a06b77
3 changed files with 53 additions and 49 deletions

View file

@ -4,6 +4,7 @@ import { isUdels } from '../../util.mjs';
import { ButtonGroup } from './Forms.jsx'; import { ButtonGroup } from './Forms.jsx';
import { AudioDeviceSelector } from './AudioDeviceSelector.jsx'; import { AudioDeviceSelector } from './AudioDeviceSelector.jsx';
import { AudioEngineTargetSelector } from './AudioEngineTargetSelector.jsx'; import { AudioEngineTargetSelector } from './AudioEngineTargetSelector.jsx';
import { confirmDialog } from '../../util.mjs';
import { isTauri } from '@src/tauri.mjs'; import { isTauri } from '@src/tauri.mjs';
function Checkbox({ label, value, onChange, disabled = false }) { function Checkbox({ label, value, onChange, disabled = false }) {
@ -82,18 +83,6 @@ const fontFamilyOptions = {
const RELOAD_MSG = 'Changing this setting requires the window to reload itself. OK?'; const RELOAD_MSG = 'Changing this setting requires the window to reload itself. OK?';
function confirmDialog(msg) {
// confirm dialog is a promise in Tauri and possibly other browsers... normalize it to be a promise everywhere
return new Promise(function (resolve, reject) {
let confirmed = confirm(msg);
if (confirmed instanceof Promise) {
confirmed.then((r) => (r ? resolve(true) : reject(false)));
} else {
return confirmed ? resolve(true) : reject(false);
}
});
}
export function SettingsTab({ started }) { export function SettingsTab({ started }) {
const { const {
theme, theme,
@ -244,9 +233,11 @@ export function SettingsTab({ started }) {
<button <button
className="bg-background p-2 max-w-[300px] rounded-md hover:opacity-50" className="bg-background p-2 max-w-[300px] rounded-md hover:opacity-50"
onClick={() => { onClick={() => {
if (confirm('Sure?')) { confirmDialog('Sure?').then((r) => {
if (r) {
settingsMap.set(defaultSettings); settingsMap.set(defaultSettings);
} }
})
}} }}
> >
restore default settings restore default settings

View file

@ -97,6 +97,16 @@ export function loadModules() {
return evalScope(settingPatterns, ...modules); return evalScope(settingPatterns, ...modules);
} }
// confirm dialog is a promise in Tauri and possibly other browsers... normalize it to be a promise everywhere
export function confirmDialog(msg) {
const confirmed = confirm(msg);
if (confirmed instanceof Promise) {
return confirmed;
}
return new Promise((resolve) => {
resolve(confirmed)
})
}
let lastShared; let lastShared;
export async function shareCode(codeToShare) { export async function shareCode(codeToShare) {
@ -105,10 +115,8 @@ export async function shareCode(codeToShare) {
logger(`Link already generated!`, 'error'); logger(`Link already generated!`, 'error');
return; return;
} }
const isPublic = confirm(
'Do you want your pattern to be public? If no, press cancel and you will get just a private link.', confirmDialog('Do you want your pattern to be public? If no, press cancel and you will get just a private link.').then(async (isPublic) => {
);
// generate uuid in the browser
const hash = nanoid(12); const hash = nanoid(12);
const shareUrl = window.location.origin + window.location.pathname + '?' + hash; const shareUrl = window.location.origin + window.location.pathname + '?' + hash;
const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]); const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]);
@ -130,6 +138,9 @@ export async function shareCode(codeToShare) {
// alert(message); // alert(message);
logger(message); logger(message);
} }
})
} }
export const ReplContext = createContext(null); export const ReplContext = createContext(null);

View file

@ -4,7 +4,7 @@ import { useStore } from '@nanostores/react';
import { logger } from '@strudel/core'; import { logger } from '@strudel/core';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
import { settingsMap } from './settings.mjs'; import { settingsMap } from './settings.mjs';
import { parseJSON, supabase } from './repl/util.mjs'; import { confirmDialog, parseJSON, supabase } from './repl/util.mjs';
export let $publicPatterns = atom([]); export let $publicPatterns = atom([]);
export let $featuredPatterns = atom([]); export let $featuredPatterns = atom([]);
@ -131,7 +131,8 @@ export const userPattern = {
return this.update(newPattern.id, { ...newPattern.data, code: data.code }); return this.update(newPattern.id, { ...newPattern.data, code: data.code });
}, },
clearAll() { clearAll() {
if (!confirm(`This will delete all your patterns. Are you really sure?`)) { confirmDialog(`This will delete all your patterns. Are you really sure?`).then((r) => {
if (r == false) {
return; return;
} }
const viewingPatternData = getViewingPatternData(); const viewingPatternData = getViewingPatternData();
@ -142,6 +143,7 @@ export const userPattern = {
} }
setActivePattern(null); setActivePattern(null);
return this.create(); return this.create();
});
}, },
delete(id) { delete(id) {
const userPatterns = this.getAll(); const userPatterns = this.getAll();