-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added add-avatar component * added AddAvatar Component to create-profile index * changed typescript type variable from camel case to pascal case and removed style components from package.json * moved AddAvatar from pages folder to components folder * removed package lock and added yarn lock
- Loading branch information
1 parent
343c45c
commit badd2ea
Showing
13 changed files
with
72,522 additions
and
12,269 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
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,5 @@ | ||
import { Web3Storage } from 'web3.storage'; | ||
|
||
export const makeStorageClient = () => { | ||
return new Web3Storage({ token: process.env.WEB3STORAGE_TOKEN ?? '' }); | ||
}; |
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,110 @@ | ||
import { | ||
Button, | ||
Image, | ||
Center, | ||
useDisclosure, | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalCloseButton, | ||
ModalBody, | ||
ModalFooter, | ||
Input, | ||
} from '@chakra-ui/react'; | ||
import React, { useState } from 'react'; | ||
import { makeStorageClient } from '../../common/web3Storage'; | ||
import { | ||
ButtonGray2, | ||
ButtonGreen, | ||
} from '../../styles/ui-components/Chakra-Button'; | ||
|
||
type AddAvatarProps = { | ||
src: string; | ||
}; | ||
|
||
const circularStyles = { | ||
w: '8rem', | ||
h: '8rem', | ||
margin: 'auto', | ||
mt: '5%', | ||
borderRadius: '180px', | ||
}; | ||
|
||
const IPFS_ENDPOINT = 'https://ipfs.io/ipfs'; | ||
|
||
const AddAvatar = ({ src }: AddAvatarProps) => { | ||
const [hoverImage, setHoverImage] = useState(false); | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const [file, setFile] = useState<string>(); | ||
const [tempFile, setTempFile] = useState<File>(); | ||
const web3Storage = makeStorageClient(); | ||
|
||
const toggleHover = () => { | ||
setHoverImage((prev) => !prev); | ||
}; | ||
|
||
const handleImageChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const { currentTarget } = event; | ||
if (currentTarget.files) { | ||
setTempFile(currentTarget.files[0]); | ||
} | ||
}; | ||
|
||
const submitProfilePicture = async () => { | ||
if (tempFile) { | ||
try { | ||
const cid = await web3Storage.put([tempFile], { | ||
maxRetries: 3, | ||
}); | ||
/* | ||
* TODO: | ||
* - Add the cid to the database | ||
*/ | ||
setFile(`${IPFS_ENDPOINT}/${cid}/${tempFile.name}`); | ||
toggleHover(); | ||
onClose(); | ||
} catch (e) { | ||
console.error('uploading image', e); | ||
} | ||
} | ||
}; | ||
|
||
return hoverImage ? ( | ||
<> | ||
<Center | ||
{...circularStyles} | ||
bgImage={file ?? src} | ||
bgSize="cover" | ||
bgRepeat="no-repeat" | ||
opacity={0.5} | ||
onMouseLeave={toggleHover} | ||
> | ||
<ButtonGray2 onClick={onOpen}>edit</ButtonGray2> | ||
</Center> | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Set new Profile pic</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<Input type="file" onChange={handleImageChange}></Input> | ||
</ModalBody> | ||
<ModalFooter> | ||
<ButtonGray2 onClick={onClose}>Close</ButtonGray2> | ||
<ButtonGreen onClick={submitProfilePicture}>Submit</ButtonGreen> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
) : ( | ||
<Image | ||
{...circularStyles} | ||
src={file ?? src} | ||
alt="developer" | ||
onMouseEnter={toggleHover} | ||
/> | ||
); | ||
}; | ||
|
||
export default AddAvatar; |
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
Oops, something went wrong.
badd2ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: