Skip to content

Commit

Permalink
Add disable state for buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
projkov committed Jun 27, 2024
1 parent a73a154 commit 35db16d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ button:hover {
cursor: pointer;
}

button:disabled {
opacity: 0.6;
cursor: not-allowed;
}

.input {
width: 100%;
padding: 10px;
Expand Down
8 changes: 4 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Loader from './components/loader';
const App: React.FC = () => {
const { url, handleUrlChange, handleFetch,
resource, expression, setExpression, setResource,
handleExecute, result, handleShare, isLoading } = useFHIRPathUI();
handleExecute, result, handleShare, isLoading, isExecuteActive, isGetResourceActive, isShareActive } = useFHIRPathUI();

return (
<div className="App">
Expand All @@ -19,7 +19,7 @@ const App: React.FC = () => {
<>
<div className="resourceBlock">
<input className="input" type="url" value={url} onChange={handleUrlChange} />
<button onClick={handleFetch}><FileArrowDown fontSize={24}/></button>
<button onClick={handleFetch} disabled={!isGetResourceActive}><FileArrowDown fontSize={24}/></button>
</div>
<Editor height="100vh" defaultLanguage="json" value={resource} onChange={(value) => setResource(value as string)} />
</>
Expand All @@ -31,8 +31,8 @@ const App: React.FC = () => {
</div>
</Allotment>
<div className="buttonsBlock">
<button onClick={handleExecute}><Play fontSize={24} /></button>
<button onClick={handleShare}><ShareFat fontSize={24} /></button>
<button onClick={handleExecute} disabled={!isExecuteActive}><Play fontSize={24} /></button>
<button onClick={handleShare} disabled={!isShareActive}><ShareFat fontSize={24} /></button>
</div>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export function useFHIRPathUI() {
const [result, setResult] = useState<string>('');
const [shareLink, setShareLink] = useState<string>('');
const [isLoading, setIsLoading] = useState<boolean>(false);
const isGetResourceActive = url !== ''
const isExecuteActive = resource !== '' && expression !== ''
const isShareActive = url !== '' && expression !== ''

const handleFetch = async () => {
setIsLoading(true)
Expand Down Expand Up @@ -74,5 +77,8 @@ export function useFHIRPathUI() {
setResource,
setExpression,
isLoading,
isExecuteActive,
isGetResourceActive,
isShareActive
}
}

0 comments on commit 35db16d

Please sign in to comment.