-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename note -> toast and touch ups to simplify code * Clean up the packages panel and install deps
- Loading branch information
Showing
6 changed files
with
163 additions
and
163 deletions.
There are no files selected for viewing
126 changes: 0 additions & 126 deletions
126
packages/web/src/components/apps/package-install-note.tsx
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
packages/web/src/components/apps/package-install-toast.tsx
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,112 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { CircleAlertIcon, InfoIcon, Loader2Icon, XIcon } from 'lucide-react'; | ||
|
||
import { usePackageJson } from './use-package-json'; | ||
import { useLogs } from './use-logs'; | ||
import { Button } from '@srcbook/components/src/components/ui/button'; | ||
import { cn } from '@/lib/utils'; | ||
|
||
const ToastWrapper: React.FC<{ showToast: boolean; children: React.ReactNode }> = ({ | ||
showToast, | ||
children, | ||
}) => ( | ||
<div | ||
className={cn( | ||
'absolute bottom-4 left-4 z-20 bg-muted border flex items-center gap-4 p-4', | ||
'rounded-lg transition-all duration-150 ease-in-out', | ||
{ | ||
'opacity-0 -bottom-8': !showToast, | ||
}, | ||
)} | ||
> | ||
{children} | ||
</div> | ||
); | ||
|
||
const PackageInstallToast: React.FunctionComponent = () => { | ||
const { togglePane } = useLogs(); | ||
const { status, npmInstall, nodeModulesExists } = usePackageJson(); | ||
const [showToast, setShowToast] = useState(false); | ||
|
||
useEffect(() => { | ||
if (nodeModulesExists === false && (status === 'idle' || status === 'complete')) { | ||
setShowToast(true); | ||
} | ||
}, [nodeModulesExists, status]); | ||
|
||
switch (status) { | ||
case 'installing': | ||
return ( | ||
<ToastWrapper showToast={showToast}> | ||
<Loader2Icon size={18} className="animate-spin" /> | ||
<span className="select-none">Installing Packages...</span> | ||
|
||
<Button | ||
className="active:translate-y-0" | ||
onClick={() => { | ||
alert('todo'); | ||
setShowToast(false); | ||
}} | ||
> | ||
Cancel | ||
</Button> | ||
</ToastWrapper> | ||
); | ||
|
||
case 'failed': | ||
return ( | ||
<ToastWrapper showToast={showToast}> | ||
<CircleAlertIcon size={18} /> | ||
<span className="font-medium select-none">Packages failed to install</span> | ||
|
||
<Button | ||
className="active:translate-y-0" | ||
onClick={() => { | ||
togglePane(); | ||
setShowToast(false); | ||
}} | ||
> | ||
More info | ||
</Button> | ||
|
||
<Button | ||
variant="secondary" | ||
size="icon" | ||
onClick={() => setShowToast(false)} | ||
className="active:translate-y-0" | ||
> | ||
<XIcon size={18} /> | ||
</Button> | ||
</ToastWrapper> | ||
); | ||
|
||
case 'idle': | ||
case 'complete': | ||
return ( | ||
<ToastWrapper showToast={showToast}> | ||
<InfoIcon size={18} /> | ||
<span className="select-none">Packages need to be installed</span> | ||
|
||
<div className="flex items-center gap-2"> | ||
<Button | ||
className="active:translate-y-0" | ||
onClick={() => npmInstall().then(() => setShowToast(false))} | ||
> | ||
Install | ||
</Button> | ||
|
||
<Button | ||
variant="secondary" | ||
size="icon" | ||
onClick={() => setShowToast(false)} | ||
className="active:translate-y-0" | ||
> | ||
<XIcon size={18} /> | ||
</Button> | ||
</div> | ||
</ToastWrapper> | ||
); | ||
} | ||
}; | ||
|
||
export default PackageInstallToast; |
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 |
---|---|---|
@@ -1,47 +1,57 @@ | ||
import { Button } from '@srcbook/components/src/components/ui/button'; | ||
import { usePackageJson } from '../use-package-json'; | ||
|
||
export default function SettingsPanel() { | ||
export default function PackagesPanel() { | ||
const { status, output, npmInstall, clearNodeModules, nodeModulesExists } = usePackageJson(); | ||
|
||
return ( | ||
<div className="flex flex-col gap-4 px-5 w-[360px]"> | ||
<p className="text-sm text-tertiary-foreground"> | ||
Clear your node_modules, re-install packages and inspect the output logs from{' '} | ||
<pre>npm install</pre> | ||
</p> | ||
<div> | ||
<Button onClick={() => npmInstall()} disabled={status === 'installing'}> | ||
Run npm install | ||
</Button> | ||
</div> | ||
<div> | ||
<Button | ||
onClick={() => npmInstall(['uuid'])} | ||
variant="secondary" | ||
disabled={status === 'installing'} | ||
> | ||
Run npm install uuid | ||
</Button> | ||
</div> | ||
<div> | ||
exists={JSON.stringify(nodeModulesExists)} | ||
<Button | ||
onClick={() => clearNodeModules()} | ||
variant="secondary" | ||
disabled={nodeModulesExists !== true} | ||
> | ||
Clear node_modules | ||
</Button> | ||
</div> | ||
|
||
{status !== 'idle' ? ( | ||
<> | ||
<span> | ||
Status: <code>{status}</code> | ||
</span> | ||
<pre className="font-mono text-sm bg-tertiary p-2 overflow-auto rounded-md border"> | ||
<h3 className="text-sm font-medium">Logs</h3> | ||
<pre className="font-mono text-xs bg-tertiary p-2 overflow-auto rounded-md border"> | ||
{/* FIXME: disambiguate between stdout and stderr in here using n.type! */} | ||
{output.map((n) => n.data).join('\n')} | ||
</pre> | ||
</> | ||
) : null} | ||
|
||
{process.env.NODE_ENV !== 'production' && ( | ||
<> | ||
<span> | ||
Status: <code>{status}</code> | ||
</span> | ||
<div> | ||
<Button | ||
onClick={() => npmInstall(['uuid'])} | ||
variant="secondary" | ||
disabled={status === 'installing'} | ||
> | ||
Run npm install uuid | ||
</Button> | ||
</div> | ||
<div> | ||
exists={JSON.stringify(nodeModulesExists)} | ||
<Button | ||
onClick={() => clearNodeModules()} | ||
variant="secondary" | ||
disabled={nodeModulesExists !== true} | ||
> | ||
Clear node_modules | ||
</Button> | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} |
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.