start new -> upload new

This commit is contained in:
Qing 2022-06-14 21:33:42 +08:00
parent 335685d581
commit 19e7e816af
3 changed files with 40 additions and 16 deletions

View File

@ -287,20 +287,30 @@ export default function Editor(props: EditorProps) {
// Zoom reset
const resetZoom = useCallback(() => {
if (!minScale || !original || !windowSize) {
if (!minScale) {
return
}
const viewport = viewportRef.current
if (!viewport) {
throw new Error('no viewport')
return
}
const offsetX = (windowSize.width - original.width * minScale) / 2
const offsetY = (windowSize.height - original.height * minScale) / 2
viewport.setTransform(offsetX, offsetY, minScale, 200, 'easeOutQuad')
viewport.setTransform(offsetX, offsetY, minScale, 0, 'easeOutQuad')
viewport.state.scale = minScale
setScale(minScale)
setPanned(false)
}, [viewportRef, minScale, original, windowSize])
}, [viewportRef, windowSize, original.width, windowSize.height, minScale])
useEffect(() => {
setLineGroups([])
setCurLineGroup([])
setRenders([])
resetZoom()
const imageSizeLimit = Math.max(original.width, original.height)
setSizeLimit(imageSizeLimit)
}, [resetZoom, file, original])
useEffect(() => {
window.addEventListener('resize', () => {

View File

@ -1,4 +1,4 @@
import React, { useCallback, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import Selector from '../shared/Selector'
const sizes = ['720', '1080', '2000', 'Original']
@ -14,6 +14,10 @@ export default function SizeSelector(props: SizeSelectorProps) {
const [activeSize, setActiveSize] = useState<string>('Original')
const longSide: number = Math.max(originalWidth, originalHeight)
useEffect(() => {
setActiveSize('Original')
}, [originalHeight, originalWidth])
const getSizeShowName = useCallback(
(size: string) => {
if (size === 'Original') {

View File

@ -1,5 +1,5 @@
import { ArrowLeftIcon } from '@heroicons/react/outline'
import React from 'react'
import { ArrowLeftIcon, UploadIcon } from '@heroicons/react/outline'
import React, { useState } from 'react'
import { useRecoilState } from 'recoil'
import { fileState } from '../../store/Atoms'
import Button from '../shared/Button'
@ -11,20 +11,30 @@ import SettingIcon from '../Settings/SettingIcon'
const Header = () => {
const [file, setFile] = useRecoilState(fileState)
const resolution = useResolution()
const [uploadElemId] = useState(`file-upload-${Math.random().toString()}`)
const renderHeader = () => {
return (
<header>
<div style={{ visibility: file ? 'visible' : 'hidden' }}>
<Button
icon={<ArrowLeftIcon />}
onClick={() => {
setFile(undefined)
<label htmlFor={uploadElemId}>
<Button icon={<UploadIcon />} style={{ border: 0 }}>
<input
style={{ display: 'none' }}
id={uploadElemId}
name={uploadElemId}
type="file"
onChange={ev => {
const newFile = ev.currentTarget.files?.[0]
if (newFile) {
setFile(newFile)
}
}}
style={{ border: 0 }}
>
{resolution === 'desktop' ? 'Start New' : undefined}
accept="image/png, image/jpeg"
/>
{resolution === 'desktop' ? 'Upload New' : undefined}
</Button>
</label>
</div>
<div className="header-icons-wrapper">