-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sk.cl.upload site image #295
Changes from 17 commits
8e8664a
f48c868
e6d2887
c84d561
a8a7a70
4b273bf
4d7d806
7fb2dbf
4848ff2
e0d6fa0
00221a4
8544e7f
0725e43
94f36db
ff61cc6
d821212
6c5870d
9b32bbd
8516c61
92ad6bc
26d744a
3e2c9cc
213a763
9b62fb8
337a412
730435f
2434898
cbdf5e0
37cf810
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import { site } from '../../constants'; | |
import { n } from '../../utils/stringFormat'; | ||
import { isSFTT } from '../../utils/isCheck'; | ||
import { getCommonName } from '../../utils/treeFunctions'; | ||
import UploadSiteImageButton from '../uploadSiteImageButton'; | ||
|
||
const TreeHeader = styled.div` | ||
text-transform: capitalize; | ||
|
@@ -163,6 +164,10 @@ export const TreeInfo: React.FC<TreeProps> = ({ | |
isAdopted={isAdopted} | ||
/> | ||
|
||
{userOwnsTree && treePresent && ( | ||
<TreePageUploadSiteImageButton siteData={siteData} /> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ I think we decided to allow anybody to upload images for a site, so we don't need to check if |
||
|
||
{userOwnsTree && treePresent && ( | ||
<StewardshipContainer> | ||
<Typography.Title level={3}> | ||
|
@@ -235,3 +240,13 @@ const TreePageShareButton: React.FC<TreePageShareButtonProps> = ({ | |
/> | ||
); | ||
}; | ||
|
||
interface TreeUploadProps { | ||
readonly siteData: SiteProps; | ||
} | ||
|
||
const TreePageUploadSiteImageButton: React.FC<TreeUploadProps> = ({ | ||
siteData, | ||
}) => { | ||
return <UploadSiteImageButton siteEntryId={siteData.entries[0].id} />; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Just curious, how come we have this extra component rather than directly using |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React, { useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { Modal } from 'antd'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { site } from '../../constants'; | ||
import { n } from '../../utils/stringFormat'; | ||
import { GreenButton, StyledClose, SubmitButton } from '../themedComponents'; | ||
import { InboxOutlined } from '@ant-design/icons'; | ||
import { message, Upload } from 'antd'; | ||
import { UploadProps } from 'antd/lib/upload/interface'; | ||
import { LIGHT_GREEN, LIGHT_GREY } from '../../utils/colors'; | ||
import protectedApiClient from '../../api/protectedApiClient'; | ||
|
||
const { Dragger } = Upload; | ||
|
||
const StyledInboxOutline = styled(InboxOutlined)` | ||
color: black; | ||
`; | ||
|
||
const ConfirmUpload = styled(SubmitButton)` | ||
margin: 10px; | ||
padding-left: 10px; | ||
|
||
& :hover { | ||
background-color: ${LIGHT_GREY}; | ||
} | ||
`; | ||
|
||
interface UploadImageProps { | ||
readonly siteEntryId: number; | ||
} | ||
|
||
const UploadSiteImageButton: React.FC<UploadImageProps> = ({ siteEntryId }) => { | ||
const { t } = useTranslation(n(site, ['treeInfo']), { | ||
nsMode: 'fallback', | ||
}); | ||
const [showMenu, setShowMenu] = useState(false); | ||
let imageToUpload: string | ArrayBuffer | null; | ||
|
||
const props: UploadProps = { | ||
name: 'file', | ||
multiple: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 Do we want to allow users to upload multiple images at a time? It'd be nice quality of life feature for users, but it'd take a bit more work to upload each image and handle individual errors. If not, I think we should add the |
||
beforeUpload: async (file) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Just curious, did making these functions |
||
const reader = new FileReader(); | ||
reader.addEventListener( | ||
'loadend', | ||
() => { | ||
imageToUpload = reader.result; | ||
}, | ||
false, | ||
); | ||
reader.readAsDataURL(file); | ||
return false; | ||
}, | ||
onChange(info) { | ||
const { status } = info.file; | ||
if (status === 'done') { | ||
message.success(`${info.file.name} file selected successfully.`); | ||
} else if (status === 'error') { | ||
message.error(`${info.file.name} file upload failed.`); | ||
} | ||
}, | ||
}; | ||
|
||
function onClickUploadSiteImage() { | ||
if (imageToUpload) { | ||
protectedApiClient.uploadImage(siteEntryId, imageToUpload).then(() => { | ||
message.success('Sent!'); | ||
setShowMenu(!showMenu); | ||
}); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<GreenButton | ||
type="text" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ Just a quick style nitpick - can we change this button's type to |
||
onClick={() => { | ||
setShowMenu(!showMenu); | ||
}} | ||
> | ||
Upload Tree Images | ||
</GreenButton> | ||
<Modal | ||
title={t('uploadSiteImage.upload_title')} // pass on as input | ||
visible={showMenu} | ||
footer={null} | ||
onCancel={() => setShowMenu(false)} | ||
closeIcon={<StyledClose />} | ||
> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 Can we add a way for users to choose to upload their images anonymously? This would make it so when we view their images, it'll hide their username (as opposed to displaying it publicly). Something like a switch or a similar input would work well - make sure to update the API route to use this value as well! |
||
<Dragger {...props}> | ||
<p className="ant-upload-drag-icon"> | ||
<StyledInboxOutline style={{ color: LIGHT_GREEN }} /> | ||
</p> | ||
<p className="ant-upload-text"> | ||
{t('uploadSiteImage.upload_drag_header')} | ||
</p> | ||
<p className="ant-upload-hint"> | ||
{t('uploadSiteImage.upload_drag_description')} | ||
</p> | ||
</Dragger> | ||
<ConfirmUpload onClick={onClickUploadSiteImage}> | ||
{t('uploadSiteImage.upload_button_message')} | ||
</ConfirmUpload> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default UploadSiteImageButton; |
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.
💯