Skip to content

Commit

Permalink
add folder input component
Browse files Browse the repository at this point in the history
  • Loading branch information
transcental committed Nov 29, 2024
1 parent a1a700f commit 888f7d9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
37 changes: 37 additions & 0 deletions src/components/folderInput.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script lang="ts">
import { open } from "@tauri-apps/plugin-dialog";
const openFolder = async () => {
const result = await open({
directory: true,
multiple: multiple,
});
if (result) {
callback(result);
}
};
export let multiple: boolean = false;
export let callback: (path: string) => void;
</script>

<button on:click={openFolder}>
<slot></slot>
</button>

<style>
button {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding: 5px;
margin: 5px;
border: 1px solid #646cff;
border-radius: 5px;
background-color: #646cff;
color: white;
}
button {
cursor: pointer;
}
</style>
33 changes: 10 additions & 23 deletions src/routes/sort-files/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { open } from "@tauri-apps/plugin-dialog";
import { DISPLAYS, type DisplayInfo } from "../../utils";
import Dropdown from "../../components/dropdown.svelte";
import FolderInput from "../../components/folderInput.svelte";
type Folder =
| { path: string; status: "checking" | "ok"; unwantedFiles?: never }
Expand All @@ -25,17 +26,12 @@
})),
);
const openFolderSelect = async () => {
const result = await open({
directory: true,
const frameFolderCallback = async (result: string) => {
folders.push({
path: result,
status: "checking",
});
if (result) {
folders.push({
path: result,
status: "checking",
});
checkFolder(result);
}
checkFolder(result);
};
const checkFolder = (path: string) => {
Expand All @@ -56,13 +52,8 @@
});
};
const openFinalFolderSelect = async () => {
const result = await open({
directory: true,
});
if (result) {
finalFolder = result;
}
const finalFolderCallback = async (result: string) => {
finalFolder = result;
};
const removeFolder = (folder: string) => {
Expand Down Expand Up @@ -113,9 +104,7 @@
<small
>These should be selected in the order you want the animation built in</small
>
<button onclick={openFolderSelect} id="folders" name="folders"
>Select Folder</button
>
<FolderInput callback={frameFolderCallback}>Select Folder</FolderInput>
{#if folders.length > 0}
<ul>
{#each folders as folder (folder)}
Expand Down Expand Up @@ -208,9 +197,7 @@
<div class="column form-input">
<h4>Final Frame Folder</h4>
<small>Where should the final frame sequence be saved</small>
<button onclick={openFinalFolderSelect} id="final" name="final"
>Select Folder</button
>
<FolderInput callback={finalFolderCallback}>Select Folder</FolderInput>
{#if finalFolder}
<small><code>{finalFolder}</code></small>
{/if}
Expand Down

0 comments on commit 888f7d9

Please sign in to comment.