Add disable attribute for no permission buttons and shorten query param names

This commit is contained in:
thiloho
2024-10-19 17:55:02 +02:00
parent 185aeea4e5
commit b1a59e38c1
22 changed files with 292 additions and 147 deletions

View File

@@ -1,6 +1,8 @@
<script lang="ts">
import { deserialize, applyAction } from "$app/forms";
import { textareaScrollTop, previewContent } from "$lib/runes.svelte";
import LoadingSpinner from "$lib/components/LoadingSpinner.svelte";
import { LOADING_DELAY } from "$lib/utils";
const {
apiPrefix,
@@ -10,6 +12,8 @@
}: { apiPrefix: string; label: string; name: string; content: string } = $props();
let mainContentTextarea: HTMLTextAreaElement;
let loadingDelay: number;
let pasting = $state(false);
const updateScrollPercentage = () => {
const { scrollTop, scrollHeight, clientHeight } = mainContentTextarea;
@@ -28,6 +32,8 @@
if (!fileObject) return;
loadingDelay = window.setTimeout(() => (pasting = true), LOADING_DELAY);
const formData = new FormData();
formData.append("file", fileObject);
@@ -48,20 +54,29 @@
const target = event.target as HTMLTextAreaElement;
const markdownToInsert = `![](${fileUrl})`;
const cursorPosition = target.selectionStart;
const newContent = target.value.slice(0, target.selectionStart) + markdownToInsert;
target.value.slice(target.selectionStart);
const newContent =
target.value.slice(0, cursorPosition) +
markdownToInsert +
target.value.slice(cursorPosition);
target.value = newContent;
previewContent.value = newContent;
const newCursorPosition = cursorPosition + markdownToInsert.length;
target.setSelectionRange(newCursorPosition, newCursorPosition);
target.focus();
} else {
return;
}
window.clearTimeout(loadingDelay);
pasting = false;
return;
};
</script>
{#if pasting}
<LoadingSpinner />
{/if}
<label>
{label}:
<textarea