-
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.
Merge pull request #162 from openstreetmap-polska/test-image-gallery
Add image gallery, photo upload, and photo report
- 2024-10-12
- 2024-06-30
- 2024-05-08
- 2024-04-20
- 2024-03-15
- 2024-02-20
- 2024-02-15
- 2024-02-13
- 2024-02-13-glitch
- 2024-02-13-crashes
- 2024-02-12
- 2024-02-12-fixEditing
- 2024-02-10
- 2024-02-10-selfHostedBadges
- 2024-02-10-fixRedirectUrl
- 2024-02-09
- 2024-02-09-deployFix
- 2024-02-08
- 2024-02-07
- 2024-01-28
- 2024-01-17
- 2024-01-14
- 2024-01-14-fix-auth-url
- 2023-12-24-vite
- 2023-12-23
Showing
15 changed files
with
477 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,104 @@ | ||
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 { initialModalState, ModalType } from "src/model/modal"; | ||
import { mdiArrowLeftBold, mdiSend } from "@mdi/js"; | ||
import Icon from "@mdi/react"; | ||
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, setModalState } = 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((response) => { | ||
if (response.ok) { | ||
closeSidebar(); | ||
setModalState({ | ||
...initialModalState, | ||
visible: true, | ||
type: ModalType.ThanksForReport, | ||
}); | ||
} else { | ||
const errorMessage = `${response} <br> status: ${response.status} ` | ||
+ `${response.statusText} <br> ${response.body}`; | ||
throw Error(errorMessage); | ||
} | ||
}) | ||
.catch((error) => { | ||
closeSidebar(); | ||
setModalState({ | ||
...initialModalState, | ||
visible: true, | ||
type: ModalType.Error, | ||
errorMessage: error, | ||
}); | ||
}); | ||
}; | ||
|
||
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> | ||
<p> | ||
{t("photo.report_long_text")} | ||
</p> | ||
<Button | ||
m={2} | ||
onClick={() => setSidebarAction(SidebarAction.showDetails)} | ||
> | ||
<Icon path={mdiArrowLeftBold} size={0.8} className="icon" /> | ||
<span>{t("footer.cancel")}</span> | ||
</Button> | ||
<Button m={2} onClick={() => sendReport(data.photoId)}> | ||
<Icon path={mdiSend} size={0.8} className="icon" /> | ||
<span>{t("photo.send_report")}</span> | ||
</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,159 @@ | ||
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 store from "store"; | ||
import { initialModalState, ModalType } from "src/model/modal"; | ||
import { mdiArrowLeftBold, mdiFileDocumentRemove, mdiFileSend } from "@mdi/js"; | ||
import Icon from "@mdi/react"; | ||
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, setModalState } = 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 | ||
mb={2} | ||
onClick={() => setSidebarAction(SidebarAction.showDetails)} | ||
> | ||
<Icon path={mdiArrowLeftBold} size={0.8} className="icon" /> | ||
<span>{t("footer.cancel")}</span> | ||
</Button> | ||
<p className="block">{t("photo.license")}</p> | ||
<p className="block">{t("photo.license_short_description")}</p> | ||
{(selectedImage !== null && ( | ||
<div> | ||
<img | ||
alt="not found" | ||
width="250px" | ||
src={URL.createObjectURL(selectedImage)} | ||
/> | ||
<br /> | ||
<div> | ||
<Button | ||
m={2} | ||
color="danger" | ||
onClick={() => setSelectedImage(null)} | ||
> | ||
<Icon path={mdiFileDocumentRemove} size={0.8} className="icon" /> | ||
<span>{t("photo.remove")}</span> | ||
</Button> | ||
<Button | ||
m={2} | ||
color="success" | ||
onClick={() => { | ||
const url = auth?.options().url; | ||
const storageKey = `${url}oauth2_access_token`; | ||
const oauth2AccessToken = store.get(storageKey); | ||
if (!oauth2AccessToken || !auth || !auth.authenticated()) { | ||
const errorMessage = `auth.authenticated()=${auth?.authenticated()} ` | ||
+ `<br> oauth2AccessToken=${oauth2AccessToken}`; | ||
closeSidebar(); | ||
setModalState({ | ||
...initialModalState, | ||
visible: true, | ||
type: ModalType.Error, | ||
errorMessage, | ||
}); | ||
} | ||
const fd = new FormData(); | ||
fd.append("node_id", data.osmId); | ||
fd.append("file_license", "CC0"); | ||
fd.append( | ||
"oauth2_credentials", | ||
JSON.stringify({ | ||
access_token: oauth2AccessToken, | ||
token_type: "Bearer", | ||
scope: "read_prefs", | ||
}), | ||
); | ||
fd.append("file", selectedImage); | ||
fetch(`${backendBaseUrl}/api/v1/photos/upload`, { | ||
method: "POST", | ||
body: fd, | ||
}) | ||
.then((response) => { | ||
if (response.ok) { | ||
closeSidebar(); | ||
setModalState({ | ||
...initialModalState, | ||
visible: true, | ||
type: ModalType.ThanksForPhoto, | ||
}); | ||
} else { | ||
const errorMessage = `${response} <br> status: ${response.status} ` | ||
+ `${response.statusText} <br> ${response.body}`; | ||
throw Error(errorMessage); | ||
} | ||
}) | ||
.catch((error) => { | ||
closeSidebar(); | ||
setModalState({ | ||
...initialModalState, | ||
visible: true, | ||
type: ModalType.Error, | ||
errorMessage: error, | ||
}); | ||
}); | ||
}} | ||
> | ||
<Icon path={mdiFileSend} size={0.8} className="icon" /> | ||
<span>{t("photo.upload")}</span> | ||
</Button> | ||
</div> | ||
</div> | ||
)) || ( | ||
<input | ||
type="file" | ||
accept=".jpeg,.jpg,.png,.webp" | ||
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
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