-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
12 changed files
with
303 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Test builds | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test-client-build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Build config | ||
run: "yarn workspace @snailycad/config build" | ||
|
||
- name: Build schemas | ||
run: "yarn workspace @snailycad/schemas build" | ||
|
||
- name: Run build | ||
run: "yarn workspace @snailycad/client build" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as React from "react"; | ||
import Cropper from "react-cropper"; | ||
import type CropperJS from "cropperjs"; | ||
import { Button } from "components/Button"; | ||
import { useTranslations } from "use-intl"; | ||
import { Modal } from "./Modal"; | ||
|
||
interface Props { | ||
onSuccess: (url: Blob, filename: string) => void; | ||
onClose: () => void; | ||
isOpen: boolean; | ||
image: File | null; | ||
options?: { width?: number; height?: number; aspectRatio: number }; | ||
} | ||
|
||
export const CropImageModal = ({ onSuccess, image, isOpen = false, onClose, options }: Props) => { | ||
const common = useTranslations("Common"); | ||
const t = useTranslations("Errors"); | ||
|
||
const [src, setSrc] = React.useState(null); | ||
const [cropper, setCropper] = React.useState<CropperJS>(); | ||
const width = !src ? 450 : options?.width ?? 900; | ||
const height = options?.height ?? 400; | ||
const aspectRatio = options?.aspectRatio ?? 1; | ||
|
||
React.useEffect(() => { | ||
if (!image) return; | ||
|
||
const reader = new FileReader(); | ||
reader.onload = () => { | ||
setSrc(reader.result as any); | ||
}; | ||
reader.readAsDataURL(image); | ||
}, [image]); | ||
|
||
const getCropData = () => { | ||
if (!image) return; | ||
|
||
if (typeof cropper !== "undefined") { | ||
cropper.getCroppedCanvas().toBlob((blob) => { | ||
if (!blob) return; | ||
|
||
onSuccess?.(blob, image.name); | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal modalStyles={{ width }} title="Crop image" isOpen={isOpen} onClose={onClose}> | ||
{src ? ( | ||
<Cropper | ||
style={{ height, width: "100%" }} | ||
zoomTo={0.5} | ||
initialAspectRatio={aspectRatio} | ||
src={src} | ||
viewMode={1} | ||
aspectRatio={aspectRatio} | ||
minCropBoxHeight={80} | ||
minCropBoxWidth={80} | ||
background={false} | ||
responsive | ||
autoCropArea={1} | ||
checkOrientation={false} // https://github.com/fengyuanchen/cropperjs/issues/671 | ||
onInitialized={(instance) => { | ||
setCropper(instance); | ||
}} | ||
guides | ||
/> | ||
) : ( | ||
<p className="my-3">{t("selectImageFirst")}</p> | ||
)} | ||
|
||
<div className="flex items-center justify-end gap-2 mt-2"> | ||
<Button variant="cancel" onClick={onClose}> | ||
{common("cancel")} | ||
</Button> | ||
<Button disabled={!image} className="flex items-center" onClick={getCropData}> | ||
{common("save")} | ||
</Button> | ||
</div> | ||
</Modal> | ||
); | ||
}; |
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.