-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial changes for allowing uploads of photos
- Loading branch information
Showing
9 changed files
with
276 additions
and
36 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
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,69 @@ | ||
import React, { FC } from "react"; | ||
import { Button, Card, Image } from "react-bulma-components"; | ||
import { useTranslation } from "react-i18next"; | ||
import { DefibrillatorData } from "src/model/defibrillatorData"; | ||
import SidebarAction from "src/model/sidebarAction"; | ||
import { CloseSidebarButton } from "./buttons"; | ||
import { accessColourClass } from "./access"; | ||
import { useAppContext } from "../../appContext"; | ||
import { backendBaseUrl } from "../../backend"; | ||
|
||
interface DefibrillatorDetailsProps { | ||
data: DefibrillatorData | null, | ||
closeSidebar: () => void, | ||
} | ||
|
||
const PhotoReport: FC<DefibrillatorDetailsProps> = (props) => { | ||
const { t } = useTranslation(); | ||
const { | ||
data, closeSidebar, | ||
} = props; | ||
const { setSidebarAction } = useAppContext(); | ||
if (data === null) return null; | ||
const accessText = data.tags.access ? ` - ${t(`access.${data.tags.access}`)}` : ""; | ||
const sendReport = (photoId: string | undefined) => { | ||
if (photoId === undefined) { | ||
console.error("Photo id is undefined. Report issue to the maintainers."); | ||
return; | ||
} | ||
console.log("Reported photo:", photoId); | ||
fetch(`${backendBaseUrl}/api/v1/photos/report`, { | ||
method: "POST", | ||
body: `id=${encodeURIComponent(photoId)}`, | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", | ||
}, | ||
}) | ||
.then(() => console.log("uploaded")) // todo: add error handling | ||
.catch((error) => console.log(error)); | ||
closeSidebar(); | ||
}; | ||
|
||
return ( | ||
<div className="sidebar" id="sidebar-div"> | ||
<Card> | ||
<Card.Header | ||
id="sidebar-header" | ||
shadowless | ||
className={accessColourClass(data.tags.access)} | ||
alignItems="center" | ||
> | ||
<Image m={2} className="icon" src="./img/logo-aed.svg" color="white" alt="" size={48} /> | ||
<span | ||
className="is-size-5 py-2 has-text-weight-light" | ||
id="sidebar-caption" | ||
> | ||
{t("sidebar.caption_info") + accessText} | ||
</span> | ||
<CloseSidebarButton closeSidebarFunction={closeSidebar} /> | ||
</Card.Header> | ||
<Card.Content> | ||
<Button m={2} onClick={() => setSidebarAction(SidebarAction.showDetails)}>{t("cancel")}</Button> | ||
<Button m={2} onClick={() => sendReport(data.photoId)}>{t("photo.send_report")}</Button> | ||
</Card.Content> | ||
</Card> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PhotoReport; |
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,94 @@ | ||
import React, { FC, useState } from "react"; | ||
import { Button, Card, Image } from "react-bulma-components"; | ||
import { useTranslation } from "react-i18next"; | ||
import { DefibrillatorData } from "src/model/defibrillatorData"; | ||
import SidebarAction from "src/model/sidebarAction"; | ||
import { CloseSidebarButton } from "./buttons"; | ||
import { accessColourClass } from "./access"; | ||
import { useAppContext } from "../../appContext"; | ||
import { backendBaseUrl } from "../../backend"; | ||
|
||
interface DefibrillatorDetailsProps { | ||
data: DefibrillatorData | null, | ||
closeSidebar: () => void, | ||
} | ||
|
||
const PhotoUpload: FC<DefibrillatorDetailsProps> = (props) => { | ||
const { t } = useTranslation(); | ||
const { | ||
data, closeSidebar, | ||
} = props; | ||
const { authState: { auth }, setSidebarAction } = useAppContext(); | ||
const [selectedImage, setSelectedImage] = useState<File | null>(null); | ||
if (data === null) return null; | ||
const accessText = data.tags.access ? ` - ${t(`access.${data.tags.access}`)}` : ""; | ||
|
||
return ( | ||
<div className="sidebar" id="sidebar-div"> | ||
<Card> | ||
<Card.Header | ||
id="sidebar-header" | ||
shadowless | ||
className={accessColourClass(data.tags.access)} | ||
alignItems="center" | ||
> | ||
<Image m={2} className="icon" src="./img/logo-aed.svg" color="white" alt="" size={48} /> | ||
<span | ||
className="is-size-5 py-2 has-text-weight-light" | ||
id="sidebar-caption" | ||
> | ||
{t("sidebar.caption_info") + accessText} | ||
</span> | ||
<CloseSidebarButton closeSidebarFunction={closeSidebar} /> | ||
</Card.Header> | ||
<Card.Content> | ||
<Button m={2} onClick={() => setSidebarAction(SidebarAction.showDetails)}>{t("cancel")}</Button> | ||
{selectedImage !== null && ( | ||
<div> | ||
<img | ||
alt="not found" | ||
width="250px" | ||
src={URL.createObjectURL(selectedImage)} | ||
/> | ||
<br /> | ||
<Button onClick={() => setSelectedImage(null)}>{t("photo.remove")}</Button> | ||
<Button | ||
m={2} | ||
onClick={() => { | ||
console.log(selectedImage); | ||
const fd = new FormData(); | ||
fd.append("node_id", data.osmId); | ||
fd.append("file_license", "CC0"); | ||
fd.append( | ||
"oauth2_credentials", | ||
JSON.stringify({ access_token: auth?.options().access_token || "test" }), | ||
This comment has been minimized.
Sorry, something went wrong. |
||
); | ||
fd.append("file", selectedImage); | ||
fetch(`${backendBaseUrl}/api/v1/photos/upload`, { | ||
method: "POST", | ||
body: fd, | ||
}) | ||
.then(() => console.log("uploaded")) // todo: add error handling | ||
.catch((error) => console.log(error)); | ||
}} | ||
> | ||
{t("photo.upload_photo")} | ||
</Button> | ||
</div> | ||
)} | ||
<input | ||
type="file" | ||
name="myImage" | ||
onChange={(event) => { | ||
const { files } = event.target; | ||
console.log(files); | ||
setSelectedImage(files !== null && files.length > 0 ? files[0] : null); | ||
}} | ||
/> | ||
</Card.Content> | ||
</Card> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PhotoUpload; |
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 |
---|---|---|
|
@@ -3,5 +3,7 @@ enum SidebarAction { | |
showDetails, | ||
addNode, | ||
editNode, | ||
reportPhoto, | ||
uploadPhoto, | ||
} | ||
export default SidebarAction; |
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 should be a complete credential set, not just access_token: