-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
275 additions
and
91 deletions.
There are no files selected for viewing
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,5 +1,5 @@ | ||
{ | ||
"version": "0.4.74", | ||
"version": "0.4.75", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
|
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
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
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
37 changes: 0 additions & 37 deletions
37
web/src/pages/lab/collage/components/download-one-photo.button.tsx
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
web/src/pages/lab/collage/components/download-photo.button.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,70 @@ | ||
import { Icon, ListButton } from 'konsta/react'; | ||
import { IoDownloadOutline } from 'react-icons/io5'; | ||
import { useStore } from '../store'; | ||
import convert from '../../../../core/drawing/convert'; | ||
import free from '../../../../core/drawing/free'; | ||
import download from '../../../../core/file-system/download'; | ||
import * as Root from '../../../../store'; | ||
import { useTranslation } from 'react-i18next'; | ||
import SIMPLE_FUNC from '../theme/SIMPLE'; | ||
import { Capacitor } from '@capacitor/core'; | ||
import compress from '../../../../core/file-system/compress'; | ||
import Photo from '../../../../core/photo'; | ||
|
||
const DownloadPhotoButton = () => { | ||
const { t } = useTranslation(); | ||
const { exportToJpeg, quality } = Root.useStore(); | ||
const { ratio, numberOfRow, numberOfColumn, photos, setLoading, paddingTop, paddingBottom, paddingLeft, paddingRight, marginEach } = useStore(); | ||
|
||
return ( | ||
<ListButton | ||
onClick={async () => { | ||
if (photos.length === 0) return; | ||
setLoading(true); | ||
await new Promise((resolve) => setTimeout(resolve, 100)); | ||
|
||
const groups: Photo[][] = []; | ||
for (let i = 0; i < photos.length; i += numberOfRow * numberOfColumn) { | ||
groups.push(photos.slice(i, i + numberOfRow * numberOfColumn)); | ||
} | ||
|
||
if (Capacitor.isNativePlatform()) { | ||
for (const group of groups) { | ||
const canvas = SIMPLE_FUNC(group, { ratio, numberOfRow, numberOfColumn, paddingTop, paddingBottom, paddingLeft, paddingRight, marginEach }); | ||
const filename = exportToJpeg ? 'collage.jpg' : 'collage.webp'; | ||
const data = await convert(canvas, { type: exportToJpeg ? 'image/jpeg' : 'image/webp', quality }); | ||
free(canvas); | ||
await download(filename, data); | ||
} | ||
} else if (groups.length === 1) { | ||
const canvas = SIMPLE_FUNC(groups[0], { ratio, numberOfRow, numberOfColumn, paddingTop, paddingBottom, paddingLeft, paddingRight, marginEach }); | ||
const filename = exportToJpeg ? 'collage.jpg' : 'collage.webp'; | ||
const data = await convert(canvas, { type: exportToJpeg ? 'image/jpeg' : 'image/webp', quality }); | ||
free(canvas); | ||
await download(filename, data); | ||
} else { | ||
const files: { filename: string; data: string }[] = []; | ||
await Promise.all( | ||
groups.map(async (group, index) => { | ||
const canvas = SIMPLE_FUNC(group, { ratio, numberOfRow, numberOfColumn, paddingTop, paddingBottom, paddingLeft, paddingRight, marginEach }); | ||
const filename = exportToJpeg ? `collage-${index}.jpg` : `collage-${index}.webp`; | ||
const data = await convert(canvas, { type: exportToJpeg ? 'image/jpeg' : 'image/webp', quality }); | ||
free(canvas); | ||
files.push({ filename, data }); | ||
}) | ||
); | ||
const zip = await compress(files); | ||
await download('images.zip', zip); | ||
} | ||
|
||
setLoading(false); | ||
}} | ||
> | ||
<Icon ios={<IoDownloadOutline className="w-5 h-5" />} /> | ||
<div style={{ width: 4 }} /> | ||
{t('root.download')} ({Math.ceil(photos.length / (numberOfRow * numberOfColumn))}) | ||
</ListButton> | ||
); | ||
}; | ||
|
||
export default DownloadPhotoButton; |
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,21 @@ | ||
import { Preloader } from 'konsta/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useStore } from '../store'; | ||
|
||
const Loading = () => { | ||
const { t } = useTranslation(); | ||
const { loading } = useStore(); | ||
|
||
if (!loading) return null; | ||
|
||
return ( | ||
<div className="fixed top-0 left-0 z-50 w-screen h-screen bg-gray-900 bg-opacity-50 flex justify-center items-center"> | ||
<div className="flex flex-col items-center"> | ||
<Preloader className="k-color-brand-white" /> | ||
<span className="ml-2 text-white text-sm">{t('root.processing')}</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Loading; |
This file was deleted.
Oops, something went wrong.
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
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.