Skip to content

Commit

Permalink
Update index.jsx
Browse files Browse the repository at this point in the history
added open and edit file button, also consolidate the text area into the same component
  • Loading branch information
synle committed Sep 30, 2023
1 parent 7c1fbc7 commit d19290b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
1 change: 0 additions & 1 deletion index.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ hr {
#container {
display: grid;
grid-template-columns: auto 1fr;
grid-template-rows: repeat(2, auto);
grid-gap: 2rem 1.5rem;
margin-top: 2rem;

Expand Down
80 changes: 46 additions & 34 deletions index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,15 @@ ${getEnvVars(formValue.envInputValue, formValue.osToRun, formValue.shouldAddDefa

{selectedScript.shouldShowEnvInput === true && (
<>
<div className='form-label'>Env Var Input</div>
<div>
<textarea
id='envInputValue'
name='envInputValue'
placeholder='Input'
onBlur={(e) => {
onInputChange(e.target.name, e.target.value.trim());
}}
defaultValue={consolidatedEnvInputValue}
/>
</div>
<EnhancedTextArea
id='envInputValue'
name='envInputValue'
placeholder='Env Var Input'
onBlur={(e) => {
onInputChange(e.target.name, e.target.value.trim());
}}
defaultValue={consolidatedEnvInputValue}
/>
<div className='form-label'>Add Default Env</div>
<div>
<input
Expand All @@ -427,18 +424,7 @@ ${getEnvVars(formValue.envInputValue, formValue.osToRun, formValue.shouldAddDefa
)}

{selectedScript.shouldHideOutput !== true && (
<>
<div className='form-label'>Output</div>
<div>
<textarea
id='formValueOutput'
placeholder='Output'
readOnly
value={formValueOutput}
onDoubleClick={(e) => copyTextToClipboard(e.target.value)}
/>
</div>
</>
<EnhancedTextArea id='formValueOutput' placeholder='Output' readOnly value={formValueOutput} />
)}

{selectedScript.shouldShowWindowsNotes === true && <WindowsNotesDom />}
Expand Down Expand Up @@ -489,24 +475,30 @@ function BottomContainer() {
}

function LinkButton(props) {
const { href, children, block } = props;
const { children, block, ...restProps } = props;

if (block) {
return (
<div>
<a href={href} type='button' target='_blank'>
<a {...restProps} type='button' target='_blank'>
{children}
</a>
</div>
);
}
return (
<a href={href} type='button' target='_blank'>
<a {...restProps} type='button' target='_blank'>
{children}
</a>
);
}

function ActionButton(props) {
const { children, ...restProps } = props;

return <button {...restProps}>{children}</button>;
}

function DynamicTextArea(props) {
const { url, height } = props;
const [text, setText] = useState('');
Expand All @@ -520,15 +512,31 @@ function DynamicTextArea(props) {
_load();
}, []);

const shortUrl = url.replace('https://raw.githubusercontent.com/synle/bashrc/master/.build/', '');
return <EnhancedTextArea height={height} url={url} value={text} readOnly />;
}

function EnhancedTextArea(props) {
let { url, label, height, ...restProps } = props;
label = label || props.placeholder;

let editUrl = '';

if (url) {
const shortUrl = url.replace('https://raw.githubusercontent.com/synle/bashrc/master/.build/', '');
label = label || shortUrl;

editUrl = `https://github.com/synle/bashrc/edit/master/.build/${shortUrl}`;
}

return (
<>
<div className='form-label'>
<span style={{ marginRight: '2rem' }}>{shortUrl}</span>
<LinkButton href={url}>Open</LinkButton>
<div className='form-label' style={{ display: 'flex', alignItems: 'center', gap: '2.5rem' }}>
<span>{label}</span>
<ActionButton onClick={(e) => copyTextToClipboard(e.target.value)}>Copy</ActionButton>
{editUrl && <LinkButton href={editUrl}>Edit</LinkButton>}
{url && <LinkButton href={url}>Open</LinkButton>}
</div>
<textarea value={text} readOnly placeholder={url} onDoubleClick={(e) => copyTextToClipboard(e.target.value)} style={{ height }} />
<textarea {...restProps} style={{ height }} />
</>
);
}
Expand Down Expand Up @@ -595,11 +603,15 @@ function WindowsNotesDom() {

<div className='form-label'>SFTP Mount Applications</div>
<div>
<div><strong>Using username and password</strong></div>
<div>
<strong>Using username and password</strong>
</div>
<code>\\sshfs\[email protected]</code>
</div>
<div>
<div><strong>Using id_rsa keys</strong></div>
<div>
<strong>Using id_rsa keys</strong>
</div>
<code>\\sshfs.k\[email protected]</code>
</div>
<div className='link-group'>
Expand Down

0 comments on commit d19290b

Please sign in to comment.