mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-26 04:58:27 +00:00
fixed dialog
This commit is contained in:
parent
d80c06cd55
commit
e9a0a06b77
@ -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) => {
|
||||||
settingsMap.set(defaultSettings);
|
if (r) {
|
||||||
}
|
settingsMap.set(defaultSettings);
|
||||||
|
}
|
||||||
|
})
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
restore default settings
|
restore default settings
|
||||||
|
|||||||
@ -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,31 +115,32 @@ 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) => {
|
||||||
);
|
const hash = nanoid(12);
|
||||||
// generate uuid in the browser
|
const shareUrl = window.location.origin + window.location.pathname + '?' + hash;
|
||||||
const hash = nanoid(12);
|
const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]);
|
||||||
const shareUrl = window.location.origin + window.location.pathname + '?' + hash;
|
if (!error) {
|
||||||
const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]);
|
lastShared = codeToShare;
|
||||||
if (!error) {
|
// copy shareUrl to clipboard
|
||||||
lastShared = codeToShare;
|
if (isTauri()) {
|
||||||
// copy shareUrl to clipboard
|
await writeText(shareUrl);
|
||||||
if (isTauri()) {
|
} else {
|
||||||
await writeText(shareUrl);
|
await navigator.clipboard.writeText(shareUrl);
|
||||||
|
}
|
||||||
|
const message = `Link copied to clipboard: ${shareUrl}`;
|
||||||
|
alert(message);
|
||||||
|
// alert(message);
|
||||||
|
logger(message, 'highlight');
|
||||||
} else {
|
} else {
|
||||||
await navigator.clipboard.writeText(shareUrl);
|
console.log('error', error);
|
||||||
|
const message = `Error: ${error.message}`;
|
||||||
|
// alert(message);
|
||||||
|
logger(message);
|
||||||
}
|
}
|
||||||
const message = `Link copied to clipboard: ${shareUrl}`;
|
|
||||||
alert(message);
|
})
|
||||||
// alert(message);
|
|
||||||
logger(message, 'highlight');
|
|
||||||
} else {
|
|
||||||
console.log('error', error);
|
|
||||||
const message = `Error: ${error.message}`;
|
|
||||||
// alert(message);
|
|
||||||
logger(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ReplContext = createContext(null);
|
export const ReplContext = createContext(null);
|
||||||
|
|||||||
@ -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,17 +131,19 @@ 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) => {
|
||||||
return;
|
if (r == false) {
|
||||||
}
|
return;
|
||||||
const viewingPatternData = getViewingPatternData();
|
}
|
||||||
setUserPatterns({});
|
const viewingPatternData = getViewingPatternData();
|
||||||
|
setUserPatterns({});
|
||||||
|
|
||||||
if (viewingPatternData.collection !== this.collection) {
|
if (viewingPatternData.collection !== this.collection) {
|
||||||
return { id: viewingPatternData.id, data: viewingPatternData };
|
return { id: viewingPatternData.id, data: viewingPatternData };
|
||||||
}
|
}
|
||||||
setActivePattern(null);
|
setActivePattern(null);
|
||||||
return this.create();
|
return this.create();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
delete(id) {
|
delete(id) {
|
||||||
const userPatterns = this.getAll();
|
const userPatterns = this.getAll();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user