Skip to content

Commit

Permalink
made buttons work
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutlope committed Sep 20, 2023
1 parent f3b4542 commit 5ec69ec
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## Todos v1.5

- [ ] Actually make the buttons work for download and regenerate
- [ ] Add some sample prompts
- [ ] a city view with clouds
- [ ] A beautiful landscape photo of a glacier, in the style of ansel adams
- [ ] Add 3-6 quick themes
- [ ] Clean up codebase: remove the multi thing

## Todos v2

Expand Down
16 changes: 14 additions & 2 deletions app/start/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { QrCard } from '@/components/QrCard';
import { AlertCircle } from 'lucide-react';
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert';
import LoadingDots from '@/components/ui/loadingdots';
import downloadQrCode from '@/utils/downloadQrCode';

const generateFormSchema = z.object({
url: z.string(),
Expand Down Expand Up @@ -154,8 +155,19 @@ const GeneratePage: NextPage = () => {
<div className="animate-pulse bg-gray-200 aspect-square rounded w-[552px] h-[580px]" />
)}
<div className="flex justify-center gap-5">
<Button>Download</Button>
<Button variant="outline">✨ Regenerate</Button>
<Button
onClick={() =>
downloadQrCode(response?.image_urls[0]!, 'qrCode')
}
>
Download
</Button>
<Button
variant="outline"
onClick={form.handleSubmit(handleSubmit)}
>
✨ Regenerate
</Button>
</div>
</div>
</>
Expand Down
23 changes: 23 additions & 0 deletions utils/downloadQrCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function forceDownload(blobUrl: string, filename: string) {
let a: any = document.createElement('a');
a.download = filename;
a.href = blobUrl;
document.body.appendChild(a);
a.click();
a.remove();
}

export default function downloadQrCode(url: string, filename: string) {
fetch(url, {
headers: new Headers({
Origin: location.origin,
}),
mode: 'cors',
})
.then((response) => response.blob())
.then((blob) => {
let blobUrl = window.URL.createObjectURL(blob);
forceDownload(blobUrl, filename);
})
.catch((e) => console.error(e));
}

0 comments on commit 5ec69ec

Please sign in to comment.