aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/app
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--apps/mobile/app.json12
-rw-r--r--apps/mobile/app/dashboard/(tabs)/index.tsx36
-rw-r--r--apps/mobile/app/sharing.tsx34
3 files changed, 71 insertions, 11 deletions
diff --git a/apps/mobile/app.json b/apps/mobile/app.json
index e674f8b5..9df4c895 100644
--- a/apps/mobile/app.json
+++ b/apps/mobile/app.json
@@ -3,7 +3,7 @@
"name": "Hoarder App",
"slug": "hoarder",
"scheme": "hoarder",
- "version": "1.2.4",
+ "version": "1.3.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
@@ -35,13 +35,19 @@
"iosActivationRules": {
"NSExtensionActivationSupportsWebURLWithMaxCount": 1,
"NSExtensionActivationSupportsWebPageWithMaxCount": 1,
- "NSExtensionActivationSupportsImageWithMaxCount": 0,
+ "NSExtensionActivationSupportsImageWithMaxCount": 1,
"NSExtensionActivationSupportsMovieWithMaxCount": 0,
"NSExtensionActivationSupportsText": true
}
}
],
- "expo-secure-store"
+ "expo-secure-store",
+ [
+ "expo-image-picker",
+ {
+ "photosPermission": "The app access your photo gallary on your request to hoard them."
+ }
+ ]
],
"extra": {
"router": {
diff --git a/apps/mobile/app/dashboard/(tabs)/index.tsx b/apps/mobile/app/dashboard/(tabs)/index.tsx
index 7f70af6b..a840ca93 100644
--- a/apps/mobile/app/dashboard/(tabs)/index.tsx
+++ b/apps/mobile/app/dashboard/(tabs)/index.tsx
@@ -1,21 +1,45 @@
import { Platform, SafeAreaView, View } from "react-native";
import * as Haptics from "expo-haptics";
+import * as ImagePicker from "expo-image-picker";
import { useRouter } from "expo-router";
import BookmarkList from "@/components/bookmarks/BookmarkList";
import PageTitle from "@/components/ui/PageTitle";
+import useAppSettings from "@/lib/settings";
+import { useUploadAsset } from "@/lib/upload";
import { MenuView } from "@react-native-menu/menu";
import { SquarePen } from "lucide-react-native";
+import { useToast } from "@/components/ui/Toast";
function HeaderRight() {
+ const {toast} = useToast();
const router = useRouter();
+ const { settings } = useAppSettings();
+ const { uploadAsset } = useUploadAsset(settings, {
+ onError: (e) => {
+ toast({message: e, variant: "destructive"});
+ },
+ });
return (
<MenuView
- onPressAction={({ nativeEvent }) => {
+ onPressAction={async ({ nativeEvent }) => {
Haptics.selectionAsync();
if (nativeEvent.event === "note") {
router.navigate("dashboard/add-note");
} else if (nativeEvent.event === "link") {
router.navigate("dashboard/add-link");
+ } else if (nativeEvent.event === "library") {
+ const result = await ImagePicker.launchImageLibraryAsync({
+ mediaTypes: ImagePicker.MediaTypeOptions.Images,
+ quality: 0,
+ allowsMultipleSelection: false,
+ });
+ if (!result.canceled) {
+ uploadAsset({
+ type: result.assets[0].mimeType ?? "",
+ name: result.assets[0].fileName ?? "",
+ uri: result.assets[0].uri,
+ });
+ }
}
}}
actions={[
@@ -31,10 +55,18 @@ function HeaderRight() {
id: "note",
title: "New Note",
image: Platform.select({
- ios: "note",
+ ios: "note.text",
android: "ic_menu_note",
}),
},
+ {
+ id: "library",
+ title: "Photo Library",
+ image: Platform.select({
+ ios: "photo",
+ android: "ic_menu_photo",
+ }),
+ },
]}
shouldOpenOnLongPress={false}
>
diff --git a/apps/mobile/app/sharing.tsx b/apps/mobile/app/sharing.tsx
index e8b0ad09..2f9dbb27 100644
--- a/apps/mobile/app/sharing.tsx
+++ b/apps/mobile/app/sharing.tsx
@@ -2,8 +2,11 @@ import { useEffect, useState } from "react";
import { Text, View } from "react-native";
import { Link, useRouter } from "expo-router";
import { useShareIntentContext } from "expo-share-intent";
+import useAppSettings from "@/lib/settings";
import { api } from "@/lib/trpc";
+import { useUploadAsset } from "@/lib/upload";
import { z } from "zod";
+import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
type Mode =
| { type: "idle" }
@@ -11,12 +14,28 @@ type Mode =
| { type: "error" };
function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) {
- const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntentContext();
+ const onSaved = (d: ZBookmark) => {
+ invalidateAllBookmarks();
+ setMode({ type: "success", bookmarkId: d.id });
+ };
+
+ const { hasShareIntent, shareIntent, resetShareIntent } =
+ useShareIntentContext();
+ const { settings, isLoading } = useAppSettings();
+ const { uploadAsset } = useUploadAsset(settings, {
+ onSuccess: onSaved,
+ onError: () => {
+ setMode({ type: "error" });
+ },
+ });
const invalidateAllBookmarks =
api.useUtils().bookmarks.getBookmarks.invalidate;
useEffect(() => {
+ if (isLoading) {
+ return;
+ }
if (!isPending && shareIntent?.text) {
const val = z.string().url();
if (val.safeParse(shareIntent.text).success) {
@@ -25,17 +44,20 @@ function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) {
} else {
mutate({ type: "text", text: shareIntent.text });
}
+ } else if (!isPending && shareIntent?.files) {
+ uploadAsset({
+ type: shareIntent.files[0].type,
+ name: shareIntent.files[0].fileName ?? "",
+ uri: shareIntent.files[0].path,
+ });
}
if (hasShareIntent) {
resetShareIntent();
}
- }, []);
+ }, [isLoading]);
const { mutate, isPending } = api.bookmarks.createBookmark.useMutation({
- onSuccess: (d) => {
- invalidateAllBookmarks();
- setMode({ type: "success", bookmarkId: d.id });
- },
+ onSuccess: onSaved,
onError: () => {
setMode({ type: "error" });
},