-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from vitormv/add-cli-args-import
Add import for CLI arguments
- Loading branch information
Showing
12 changed files
with
269 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<script lang="ts"> | ||
import Modal from '~/components/common/Modal.svelte'; | ||
import { toast } from '@zerodevx/svelte-toast'; | ||
import { ArrowForwardOutline } from 'svelte-ionicons'; | ||
import { importFromEnvArgs } from '~/data/import/importFromEnvArgs'; | ||
export let isModalOpen = false; | ||
let textareaEl: HTMLTextAreaElement; | ||
let errorMessage = ''; | ||
function validateInput(textareaValue: string) { | ||
if (textareaValue.startsWith('export ') || textareaValue.includes('FZF_DEFAULT_OPTS')) { | ||
errorMessage = | ||
'Invalid input. Text should not start with "export" and should not contain "FZF_DEFAULT_OPTS".'; | ||
return false; | ||
} | ||
errorMessage = ''; | ||
return true; | ||
} | ||
function onClickImport() { | ||
if (!textareaEl) return; | ||
const value = textareaEl.value; | ||
if (validateInput(value)) { | ||
importFromEnvArgs(value); | ||
isModalOpen = false; | ||
textareaEl.value = ''; | ||
toast.push('Imported theme and colors!', {}); | ||
} | ||
} | ||
</script> | ||
|
||
<!-- svelte-ignore a11y-no-static-element-interactions --> | ||
<div class="wrapper" on:mousemove|stopPropagation> | ||
<Modal bind:showModal={isModalOpen}> | ||
<h2 slot="header">Import Options</h2> | ||
|
||
<div class="content"> | ||
<p style="flex: 1;"> | ||
Paste the <strong>contents</strong> of your <code>FZF_DEFAULT_OPTS</code> variable. | ||
</p> | ||
|
||
<textarea | ||
bind:this={textareaEl} | ||
on:input={() => validateInput(textareaEl.value)} | ||
placeholder="Paste only the variable contents (inside the quotes)..." | ||
></textarea> | ||
|
||
<div class="footer"> | ||
<div class="error" style="word-wrap: break-word; overflow-wrap: break-word;"> | ||
{errorMessage} | ||
</div> | ||
<button | ||
class="export btn btn-secondary" | ||
on:click={onClickImport} | ||
disabled={!textareaEl?.value.trim() || !!errorMessage} | ||
> | ||
Import <ArrowForwardOutline size="16" /> | ||
</button> | ||
</div> | ||
</div> | ||
</Modal> | ||
</div> | ||
|
||
<style lang="scss"> | ||
.content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
height: 100%; | ||
} | ||
textarea { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
.footer { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: flex-start; | ||
gap: 20px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.