This commit is contained in:
Timothy Jaeryang Baek
2026-01-06 00:05:52 +04:00
parent de9cff6b4e
commit 4cf901f519
2 changed files with 16 additions and 16 deletions
@@ -15,7 +15,7 @@
export let edit = false; export let edit = false;
export let prompt = null; export let prompt = null;
export let clone = false; export let clone = false;
export let write_access = true; export let disabled = true;
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@@ -41,7 +41,7 @@
} }
const submitHandler = async () => { const submitHandler = async () => {
if (!write_access) { if (disabled) {
toast.error($i18n.t('You do not have permission to edit this prompt.')); toast.error($i18n.t('You do not have permission to edit this prompt.'));
return; return;
} }
@@ -116,10 +116,14 @@
placeholder={$i18n.t('Title')} placeholder={$i18n.t('Title')}
bind:value={title} bind:value={title}
required required
disabled={!write_access} {disabled}
/> />
{#if write_access} {#if disabled}
<div class="text-xs shrink-0 text-gray-500">
{$i18n.t('Read Only')}
</div>
{:else}
<div class="self-center shrink-0"> <div class="self-center shrink-0">
<button <button
class="bg-gray-50 hover:bg-gray-100 text-black dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-white transition px-2 py-1 rounded-full flex gap-1 items-center" class="bg-gray-50 hover:bg-gray-100 text-black dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-white transition px-2 py-1 rounded-full flex gap-1 items-center"
@@ -135,10 +139,6 @@
</div> </div>
</button> </button>
</div> </div>
{:else}
<div class="text-xs shrink-0 text-gray-500">
{$i18n.t('Read Only')}
</div>
{/if} {/if}
</div> </div>
@@ -150,7 +150,7 @@
bind:value={command} bind:value={command}
on:input={handleCommandInput} on:input={handleCommandInput}
required required
disabled={edit || !write_access} disabled={edit || disabled}
/> />
</div> </div>
</div> </div>
@@ -170,7 +170,7 @@
bind:value={content} bind:value={content}
rows={6} rows={6}
required required
disabled={!write_access} readonly={disabled}
/> />
</div> </div>
@@ -194,13 +194,13 @@
</div> </div>
<div class="my-4 flex justify-end pb-20"> <div class="my-4 flex justify-end pb-20">
<Tooltip content={!write_access ? $i18n.t('You do not have permission to save this prompt.') : ''}> <Tooltip content={disabled ? $i18n.t('You do not have permission to save this prompt.') : ''}>
<button <button
class=" text-sm w-full lg:w-fit px-4 py-2 transition rounded-xl {loading || !write_access class=" text-sm w-full lg:w-fit px-4 py-2 transition rounded-xl {loading || disabled
? ' cursor-not-allowed bg-gray-200 text-gray-500 dark:bg-gray-700 dark:text-gray-400' ? ' cursor-not-allowed bg-gray-200 text-gray-500 dark:bg-gray-700 dark:text-gray-400'
: 'bg-black hover:bg-gray-900 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black'} flex w-full justify-center" : 'bg-black hover:bg-gray-900 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black'} flex w-full justify-center"
type="submit" type="submit"
disabled={loading || !write_access} disabled={loading || disabled}
> >
<div class=" self-center font-medium">{$i18n.t('Save & Create')}</div> <div class=" self-center font-medium">{$i18n.t('Save & Create')}</div>
{#if loading} {#if loading}
@@ -12,7 +12,7 @@
import PromptEditor from '$lib/components/workspace/Prompts/PromptEditor.svelte'; import PromptEditor from '$lib/components/workspace/Prompts/PromptEditor.svelte';
let prompt = null; let prompt = null;
let write_access = true; let disabled = true;
const onSubmit = async (_prompt) => { const onSubmit = async (_prompt) => {
console.log(_prompt); console.log(_prompt);
@@ -40,7 +40,7 @@
}); });
if (_prompt) { if (_prompt) {
write_access = _prompt.write_access ?? true; disabled = !_prompt.write_access ?? true;
prompt = { prompt = {
title: _prompt.title, title: _prompt.title,
command: _prompt.command, command: _prompt.command,
@@ -57,5 +57,5 @@
</script> </script>
{#if prompt} {#if prompt}
<PromptEditor {prompt} {onSubmit} {write_access} edit /> <PromptEditor {prompt} {onSubmit} {disabled} edit />
{/if} {/if}