Skip to content

Commit

Permalink
url input dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
lhns committed Mar 21, 2023
1 parent 750238f commit 94fa3dd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
57 changes: 57 additions & 0 deletions src/html/InputSubmit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'

class Select extends React.Component<{
label?: string,
value: string,
action: string,
placeholder?: string,
disabled?: boolean
onSubmit: (value: string) => void
}, {
value: string
}> {
constructor(props: any) {
super(props)

this.state = {
value: props.value
}
}

componentDidUpdate(prevProps: any) {
const {value} = this.props
if (value != null && value !== prevProps.value) {
this.setState(state => ({...state, value: value}))
}
}

render() {
const {label, action, placeholder, disabled, onSubmit} = this.props
const {value} = this.state ?? {}

return <div className="input-group">
{label ? <span className="input-group-text">{label}</span> : null}
<input type="text"
className="form-control"
placeholder={placeholder}
disabled={disabled}
value={value ?? ''}
onChange={event => {
const value = event.target.value
this.setState(state => ({...state, value: value}))
}}
onKeyDown={event => {
if (event.key === 'Enter') {
onSubmit(value)
}
}}/>
<button type="button"
className="btn btn-primary"
disabled={disabled}
onClick={() => onSubmit(value)}>{action}
</button>
</div>
}
}

export default Select
2 changes: 1 addition & 1 deletion src/html/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Select extends React.Component<{
label?: string,
items: string[],
selected?: string,
disabled?: Boolean
disabled?: boolean
onSelect: (item: string) => void
}, {
selected: string
Expand Down
14 changes: 12 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ReactDOM from 'react-dom/client'
import http from 'isomorphic-git/http/web'
import LightningFS from '@isomorphic-git/lightning-fs'
import MainComponent from './MainComponent'
import InputSubmit from "./html/InputSubmit"
// @ts-ignore
import * as bootstrap from 'bootstrap'
// @ts-ignore
Expand All @@ -20,8 +21,17 @@ const url: string | null = params.get('url')
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>{
url == null ?
<div>
No git url provided
<div className="container py-4">
<InputSubmit
label="Clone URL"
value=""
action="OK"
placeholder="URL"
onSubmit={(url) => {
const newUrl = new URL(window.location.href)
newUrl.searchParams.set('url', url)
window.location.href = newUrl.href
}}/>
</div> :
<MainComponent
fs={fs}
Expand Down

0 comments on commit 94fa3dd

Please sign in to comment.