forked from aeharding/voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom gallery actions (copy, save image etc) (aeharding#625)
- Loading branch information
Showing
9 changed files
with
212 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import { | ||
IonIcon, | ||
useIonActionSheet, | ||
useIonRouter, | ||
useIonToast, | ||
} from "@ionic/react"; | ||
import { | ||
bookmarkOutline, | ||
copyOutline, | ||
downloadOutline, | ||
earthOutline, | ||
ellipsisHorizontal, | ||
peopleOutline, | ||
personOutline, | ||
shareOutline, | ||
} from "ionicons/icons"; | ||
import { useBuildGeneralBrowseLink } from "../../helpers/routes"; | ||
import { getHandle } from "../../helpers/lemmy"; | ||
import { PostView } from "lemmy-js-client"; | ||
import { PageContext } from "../auth/PageContext"; | ||
import { useContext } from "react"; | ||
import { useAppDispatch, useAppSelector } from "../../store"; | ||
import { savePost } from "../post/postSlice"; | ||
import { saveError } from "../../helpers/toastMessages"; | ||
import { Browser } from "@capacitor/browser"; | ||
import { Share } from "@capacitor/share"; | ||
import { ActionButton } from "../post/actions/ActionButton"; | ||
import { StashMedia } from "capacitor-stash-media"; | ||
|
||
interface GalleryMoreActionsProps { | ||
post: PostView; | ||
imgSrc: string; | ||
} | ||
|
||
export default function GalleryMoreActions({ | ||
post, | ||
imgSrc, | ||
}: GalleryMoreActionsProps) { | ||
const router = useIonRouter(); | ||
const [presentActionSheet] = useIonActionSheet(); | ||
const buildGeneralBrowseLink = useBuildGeneralBrowseLink(); | ||
|
||
const { presentLoginIfNeeded } = useContext(PageContext); | ||
const [presentToast] = useIonToast(); | ||
const dispatch = useAppDispatch(); | ||
|
||
const postSavedById = useAppSelector((state) => state.post.postSavedById); | ||
const mySaved = postSavedById[post.post.id] ?? post.saved; | ||
|
||
function openActions() { | ||
presentActionSheet({ | ||
cssClass: "left-align-buttons", | ||
buttons: [ | ||
{ | ||
text: "Share", | ||
icon: shareOutline, | ||
handler: () => { | ||
Share.share({ url: imgSrc }); | ||
}, | ||
}, | ||
{ | ||
text: "Save Image", | ||
icon: downloadOutline, | ||
handler: () => { | ||
(async () => { | ||
try { | ||
await StashMedia.savePhoto({ url: imgSrc }); | ||
} catch (error) { | ||
presentToast({ | ||
message: "Error saving photo to device", | ||
duration: 3500, | ||
position: "bottom", | ||
color: "danger", | ||
}); | ||
|
||
throw error; | ||
} | ||
|
||
presentToast({ | ||
message: "Photo saved", | ||
duration: 3500, | ||
position: "bottom", | ||
color: "success", | ||
}); | ||
})(); | ||
}, | ||
}, | ||
{ | ||
text: "Copy Image", | ||
icon: copyOutline, | ||
handler: () => { | ||
(async () => { | ||
try { | ||
await StashMedia.copyPhotoToClipboard({ url: imgSrc }); | ||
} catch (error) { | ||
presentToast({ | ||
message: "Error copying photo to clipboard", | ||
duration: 3500, | ||
position: "bottom", | ||
color: "danger", | ||
}); | ||
|
||
throw error; | ||
} | ||
|
||
presentToast({ | ||
message: "Photo copied to clipboard", | ||
duration: 3500, | ||
position: "bottom", | ||
color: "success", | ||
}); | ||
})(); | ||
}, | ||
}, | ||
{ | ||
text: "Open in Browser", | ||
icon: earthOutline, | ||
handler: () => { | ||
Browser.open({ url: post.post.ap_id }); | ||
}, | ||
}, | ||
{ | ||
text: "Save", | ||
icon: bookmarkOutline, | ||
handler: () => { | ||
(async () => { | ||
if (presentLoginIfNeeded()) return; | ||
|
||
try { | ||
await dispatch(savePost(post.post.id, !mySaved)); | ||
} catch (error) { | ||
presentToast(saveError); | ||
|
||
throw error; | ||
} | ||
})(); | ||
}, | ||
}, | ||
{ | ||
text: getHandle(post.creator), | ||
icon: personOutline, | ||
handler: () => { | ||
router.push( | ||
buildGeneralBrowseLink(`/u/${getHandle(post.creator)}`) | ||
); | ||
}, | ||
}, | ||
{ | ||
text: getHandle(post.community), | ||
icon: peopleOutline, | ||
handler: () => { | ||
router.push( | ||
buildGeneralBrowseLink(`/c/${getHandle(post.community)}`) | ||
); | ||
}, | ||
}, | ||
{ | ||
text: "Cancel", | ||
role: "cancel", | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
return ( | ||
<ActionButton onClick={openActions}> | ||
<IonIcon icon={ellipsisHorizontal} /> | ||
</ActionButton> | ||
); | ||
} |
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