Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Dec 6, 2024
1 parent 258637e commit 7cd270a
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 85 deletions.
2 changes: 1 addition & 1 deletion ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def capacitor_pods
pod 'CapacitorLaunchNative', :path => '../../node_modules/.pnpm/capacitor-launch-native@1.0.0_@capacitor+core@6.2.0/node_modules/capacitor-launch-native'
pod 'CapacitorPluginSafeArea', :path => '../../node_modules/.pnpm/capacitor-plugin-safe-area@3.0.3_@capacitor+core@6.2.0/node_modules/capacitor-plugin-safe-area'
pod 'CapacitorReader', :path => '../../node_modules/.pnpm/capacitor-reader@0.2.0_@capacitor+core@6.2.0/node_modules/capacitor-reader'
pod 'CapacitorStashMedia', :path => '../../node_modules/.pnpm/capacitor-stash-media@2.0.1_@capacitor+core@6.2.0/node_modules/capacitor-stash-media'
pod 'CapacitorStashMedia', :path => '../../../capacitor-stash-media'
pod 'CapacitorTips', :path => '../../node_modules/.pnpm/capacitor-tips@1.0.0_@capacitor+core@6.2.0/node_modules/capacitor-tips'
end

Expand Down
14 changes: 7 additions & 7 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ PODS:
- Capacitor
- CapacitorTips (1.0.0):
- Capacitor
- SDWebImage (5.18.7):
- SDWebImage/Core (= 5.18.7)
- SDWebImage/Core (5.18.7)
- SDWebImage (5.20.0):
- SDWebImage/Core (= 5.20.0)
- SDWebImage/Core (5.20.0)

DEPENDENCIES:
- "Capacitor (from `../../node_modules/.pnpm/@capacitor+ios@6.2.0_@capacitor+core@6.2.0/node_modules/@capacitor/ios`)"
Expand All @@ -61,7 +61,7 @@ DEPENDENCIES:
- "CapacitorReader (from `../../node_modules/.pnpm/capacitor-reader@0.2.0_@capacitor+core@6.2.0/node_modules/capacitor-reader`)"
- "CapacitorShare (from `../../node_modules/.pnpm/@capacitor+share@6.0.3_@capacitor+core@6.2.0/node_modules/@capacitor/share`)"
- "CapacitorSplashScreen (from `../../node_modules/.pnpm/@capacitor+splash-screen@6.0.3_@capacitor+core@6.2.0/node_modules/@capacitor/splash-screen`)"
- "CapacitorStashMedia (from `../../node_modules/.pnpm/capacitor-stash-media@2.0.1_@capacitor+core@6.2.0/node_modules/capacitor-stash-media`)"
- CapacitorStashMedia (from `../../../capacitor-stash-media`)
- "CapacitorStatusBar (from `../../node_modules/.pnpm/@capacitor+status-bar@6.0.2_@capacitor+core@6.2.0/node_modules/@capacitor/status-bar`)"
- "CapacitorTips (from `../../node_modules/.pnpm/capacitor-tips@1.0.0_@capacitor+core@6.2.0/node_modules/capacitor-tips`)"

Expand Down Expand Up @@ -105,7 +105,7 @@ EXTERNAL SOURCES:
CapacitorSplashScreen:
:path: "../../node_modules/.pnpm/@capacitor+splash-screen@6.0.3_@capacitor+core@6.2.0/node_modules/@capacitor/splash-screen"
CapacitorStashMedia:
:path: "../../node_modules/.pnpm/capacitor-stash-media@2.0.1_@capacitor+core@6.2.0/node_modules/capacitor-stash-media"
:path: "../../../capacitor-stash-media"
CapacitorStatusBar:
:path: "../../node_modules/.pnpm/@capacitor+status-bar@6.0.2_@capacitor+core@6.2.0/node_modules/@capacitor/status-bar"
CapacitorTips:
Expand All @@ -132,8 +132,8 @@ SPEC CHECKSUMS:
CapacitorStashMedia: 10aa96dc5f874c4c27642528a4c327c46792abf2
CapacitorStatusBar: 3b9ac7d0684770522c532d1158a1434512ab1477
CapacitorTips: 2087733aea06ec041b210085395ca934c8554907
SDWebImage: f9258c58221ed854cfa0e2b80ee4033710b1c6d3
SDWebImage: 73c6079366fea25fa4bb9640d5fb58f0893facd8

PODFILE CHECKSUM: 810e83271706ad233eac03b47e2284efbdcfc205
PODFILE CHECKSUM: 095fb6bc4cfa620d894c9a6c3321dd14f0a18f85

COCOAPODS: 1.16.2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"capacitor-launch-native": "^1.0.0",
"capacitor-plugin-safe-area": "^3.0.3",
"capacitor-reader": "^0.2.0",
"capacitor-stash-media": "^2.0.1",
"capacitor-stash-media": "link:../capacitor-stash-media",
"capacitor-tips": "^1.0.0",
"colorjs.io": "^0.5.2",
"compare-versions": "^6.1.1",
Expand Down
13 changes: 2 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/features/media/gallery/GalleryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ interface IGalleryContext {
}

export const GalleryContext = createContext<IGalleryContext>({
// eslint-disable-next-line no-empty-function
open: async () => {},
close: noop,
});
Expand All @@ -58,6 +57,7 @@ export default function GalleryProvider({ children }: React.PropsWithChildren) {
);
const thumbElRef = useRef<ThumbEl>();
const [post, setPost] = useState<PostView>();
const [isVideo, setIsVideo] = useState(false);
const lightboxRef = useRef<PhotoSwipeLightbox | null>(null);
const location = useLocation();

Expand All @@ -68,6 +68,8 @@ export default function GalleryProvider({ children }: React.PropsWithChildren) {
const [videoSrc, setVideoSrc] = useState("");
const portalNode = useVideoPortalNode(videoSrc);

const videoRef = useRef<HTMLVideoElement>(null);

useEffect(() => {
return () => {
lightboxRef.current?.destroy();
Expand Down Expand Up @@ -209,10 +211,12 @@ export default function GalleryProvider({ children }: React.PropsWithChildren) {
instance.on("contentAppend", (e) => {
const { content } = e;

setVideoSrc(src);

if (thumbEl instanceof HTMLVideoElement) {
e.preventDefault();

setVideoSrc(src);
setIsVideo(true);
setVideoContainer(content.element!);

content.slide!.container.appendChild(content.element!);
Expand Down Expand Up @@ -410,6 +414,7 @@ export default function GalleryProvider({ children }: React.PropsWithChildren) {

instance.on("close", () => {
setVideoSrc("");
setIsVideo(false);
setVideoContainer(null);
});

Expand Down Expand Up @@ -447,14 +452,17 @@ export default function GalleryProvider({ children }: React.PropsWithChildren) {
thumbElRef.current && (
<GalleryPostActions
post={post}
imgSrc={videoSrc}
src={videoSrc}
alt={getAlt(thumbElRef.current)}
isVideo={isVideo}
videoRef={videoRef}
/>
)
) : (
<ImageMoreActions
imgSrc={videoSrc}
alt={getAlt(thumbElRef.current)}
videoRef={videoRef}
/>
),
actionContainer,
Expand All @@ -463,6 +471,7 @@ export default function GalleryProvider({ children }: React.PropsWithChildren) {
{videoContainer !== null && portalNode
? createPortal(
<portals.OutPortal<typeof Player>
videoRef={videoRef}
node={portalNode}
src={videoSrc}
pauseWhenNotInView={false}
Expand Down
144 changes: 90 additions & 54 deletions src/features/media/gallery/actions/GalleryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ import { useAppDispatch, useAppSelector } from "#/store";

interface GalleryActionsProps {
post?: PostView;
imgSrc: string;
src: string;
isVideo?: boolean;
}

export default function GalleryActions({ post, imgSrc }: GalleryActionsProps) {
export default function GalleryActions({
post,
src,
isVideo,
}: GalleryActionsProps) {
const router = useOptimizedIonRouter();
const openNativeBrowser = useNativeBrowser();
const [presentActionSheet] = useIonActionSheet();
Expand All @@ -56,63 +61,94 @@ export default function GalleryActions({ post, imgSrc }: GalleryActionsProps) {
presentActionSheet({
cssClass: "left-align-buttons",
buttons: compact([
{
text: "Share",
icon: getShareIcon(),
handler: () => {
(async () => {
if (!isNative()) {
Share.share({ url: imgSrc });
return;
}

try {
await StashMedia.shareImage({
url: imgSrc,
title: post ? post.post.name : "Image",
});
} catch (error) {
presentToast({
message: "Error sharing photo",
color: "danger",
position: "top",
fullscreen: true,
});

throw error;
}
})();
},
},
{
text: "Save Image",
icon: downloadOutline,
handler: () => {
(async () => {
try {
await StashMedia.savePhoto({ url: imgSrc });
} catch (error) {
presentToast({
message: "Error saving photo to device",
color: "danger",
position: "top",
fullscreen: true,
});

throw error;
}

presentToast(photoSaved);
})();
},
},
{
isVideo
? {
text: "Share Link",
icon: getShareIcon(),
handler: () => {
Share.share({ url: post?.post.ap_id });
},
}
: {
text: "Share",
icon: getShareIcon(),
handler: () => {
(async () => {
if (!isNative()) {
Share.share({ url: src });
return;
}

try {
await StashMedia.shareImage({
url: src,
title: post ? post.post.name : "Image",
});
} catch (error) {
presentToast({
message: "Error sharing photo",
color: "danger",
position: "top",
fullscreen: true,
});

throw error;
}
})();
},
},
isVideo
? {
text: "Save Video",
icon: downloadOutline,
handler: () => {
(async () => {
try {
await StashMedia.saveVideo({ url: src });
} catch (error) {
presentToast({
message: "Error saving video to device",
color: "danger",
position: "top",
fullscreen: true,
});

throw error;
}

presentToast(photoSaved);
})();
},
}
: {
text: "Save Image",
icon: downloadOutline,
handler: () => {
(async () => {
try {
await StashMedia.savePhoto({ url: src });
} catch (error) {
presentToast({
message: "Error saving photo to device",
color: "danger",
position: "top",
fullscreen: true,
});

throw error;
}

presentToast(photoSaved);
})();
},
},
!isVideo && {
text: "Copy Image",
icon: copyOutline,
handler: () => {
(async () => {
try {
await StashMedia.copyPhotoToClipboard({ url: imgSrc });
await StashMedia.copyPhotoToClipboard({ url: src });
} catch (error) {
presentToast({
message: "Error copying photo to clipboard",
Expand Down
18 changes: 12 additions & 6 deletions src/features/media/gallery/actions/GalleryPostActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@ import { GalleryContext } from "../GalleryProvider";
import AltText from "./AltText";
import GalleryActions from "./GalleryActions";
import { BottomContainer, BottomContainerActions } from "./shared";
import VideoActions from "./VideoActions";

import styles from "./GalleryPostActions.module.css";

interface GalleryPostActionsProps {
post: PostView;
imgSrc: string;
src: string;
alt?: string;
isVideo?: boolean;
videoRef?: React.RefObject<HTMLVideoElement>;
}

export default function GalleryPostActions({
post,
imgSrc,
src,
alt,
isVideo,
videoRef,
}: GalleryPostActionsProps) {
const buildGeneralBrowseLink = useBuildGeneralBrowseLink();
const router = useOptimizedIonRouter();
Expand All @@ -44,13 +49,13 @@ export default function GalleryPostActions({

async function shareImage() {
if (!isNative()) {
Share.share({ url: imgSrc });
Share.share({ url: src });
return;
}

try {
await StashMedia.shareImage({
url: imgSrc,
url: src,
title: post.post.name,
});
} catch (error) {
Expand All @@ -68,9 +73,10 @@ export default function GalleryPostActions({
return (
<BottomContainer>
<AltText alt={alt} />
{isVideo && videoRef && <VideoActions videoRef={videoRef} />}
<BottomContainerActions withBg>
<div className={styles.container} onClick={(e) => e.stopPropagation()}>
<Voting post={post} imgSrc={imgSrc} />
<Voting post={post} src={src} />
<div
onClick={() => {
close();
Expand All @@ -89,7 +95,7 @@ export default function GalleryPostActions({
</div>
<IonIcon icon={getShareIcon()} onClick={shareImage} />
{isNative() ? (
<GalleryActions post={post} imgSrc={imgSrc} />
<GalleryActions post={post} src={src} isVideo={isVideo} />
) : (
<InFeedContext.Provider value={true}>
<MoreActions post={post} />
Expand Down
Loading

0 comments on commit 7cd270a

Please sign in to comment.