Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/account/upload-profile-image.tsx
Views: 687
// Upload user avatar image12// similar to code in next/components/account/config/account/avatar.tsx34import { useState } from "react";5import { Alert, Upload } from "antd";6import ImgCrop from "antd-img-crop";7import imageToDataURL from "@cocalc/frontend/misc/image-to-data";8import { Avatar } from "./avatar/avatar";910// This is what facebook uses, and it makes11// 40x40 look very good. It takes about 20KB12// per image.1314const AVATAR_SIZE: number = 160;1516interface Props {17account_id: string;18onChange: (data) => void;19}2021export default function UploadProfileImage({ account_id, onChange }: Props) {22const [error, setError] = useState<string>("");23return (24<div>25<ImgCrop26modalTitle={"Edit Profile Image"}27cropShape="rect"28rotationSlider29maxZoom={5}30onModalOk={(file) => {31const reader = new FileReader();32reader.addEventListener(33"load",34async (e) => {35if (!e.target?.result) return; // typescript36const src = e.target.result as string;37onChange(38await imageToDataURL(39src,40AVATAR_SIZE,41AVATAR_SIZE,42"image/png",43),44);45},46false,47);48if (typeof file != "object") {49setError(50"WARNING: unable to read, since avatar is assumed to be a Blob",51);52return;53}54reader.readAsDataURL(file as any);55}}56>57<Upload.Dragger58name="file"59onDrop={(e) => {60e.preventDefault();61e.stopPropagation();62}}63>64<p className="ant-upload-drag-icon">65<Avatar account_id={account_id} size={AVATAR_SIZE/2} />66</p>67<p className="ant-upload-text">68Click or drag image to this area to upload69</p>70</Upload.Dragger>71</ImgCrop>72{error && (73<Alert74style={{ marginTop: "15px" }}75type="error"76message={error}77showIcon78/>79)}80</div>81);82}838485