Skip to content

Commit

Permalink
Back to homescreen after upload file successfull in file detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
quanvo298Wizeline committed Sep 24, 2024
1 parent 9f7c7fb commit 233020f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 10 additions & 10 deletions app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//

import { Tabs } from "expo-router";
import { router, Tabs } from "expo-router";
import type { MutableRefObject } from "react";
import React, { useRef, useState } from "react";
import HouseOutLine from "@/assets/images/house-outline.svg";
Expand All @@ -34,8 +34,6 @@ import {
} from "react-native";
import PopupMenu from "@/components/PopupMenu";
import { ThemedText } from "@/components/ThemedText";
import { fetchFiles } from "@/api/files";
import { useQueryClient } from "@tanstack/react-query";

const { width, height } = Dimensions.get("window");

Expand All @@ -45,7 +43,6 @@ export default function TabLayout() {
const [positionType, setPositionType] = useState<
"topMiddle" | "bottomLeft" | "bottomMiddle"
>("bottomMiddle");
const queryClient = useQueryClient();
const tabBarAddButtonRef = useRef(null);
const rightHeaderAddButtonRef = useRef(null);
const toggleMenu = (
Expand Down Expand Up @@ -109,6 +106,7 @@ export default function TabLayout() {
name="home"
options={{
title: "Home",
href: "/home",
tabBarIcon: ({ color, focused }) =>
focused ? (
<FontAwesome6 size={24} name="house" color={color} />
Expand Down Expand Up @@ -195,12 +193,14 @@ export default function TabLayout() {
</Tabs>
<PopupMenu
visible={menuVisible}
onClose={() => toggleMenu("topMiddle", rightHeaderAddButtonRef)}
onUploadSuccess={async () => {
await queryClient.fetchQuery({
queryKey: ["files"],
queryFn: fetchFiles,
});
onClose={() => {
toggleMenu(
"topMiddle",
tabBarAddButtonRef || rightHeaderAddButtonRef
);
}}
onUploadSuccess={() => {
router.replace("/home");
}}
position={menuPosition}
positionType={positionType}
Expand Down
8 changes: 6 additions & 2 deletions app/(tabs)/home/[fileName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
import { View, StyleSheet, TouchableOpacity, Image } from "react-native";
import { useQuery } from "@tanstack/react-query";
import { useIsMutating, useQuery } from "@tanstack/react-query";
import { getFile } from "@/api/files";
import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";
import { faEllipsis } from "@fortawesome/free-solid-svg-icons/faEllipsis";
Expand All @@ -27,6 +27,7 @@ import { Colors } from "@/constants/Colors";
import VcCard from "@/components/files/VcCard";
import BottomModal from "@/components/files/BottomModal";
import type { WalletFile } from "@/types/WalletFile";
import Loading from "@/components/LoadingButton";

interface FileDetailProps {
file: WalletFile;
Expand All @@ -46,6 +47,8 @@ const blobToBase64 = (blob: Blob): Promise<string> => {
};

const Page: React.FC<FileDetailProps> = () => {
const isMutatingFiles = useIsMutating({ mutationKey: ["filesMutation"] });

const { fileName, isRDFResourceStr, identifier } = useLocalSearchParams();
const isRDFResource: boolean = isRDFResourceStr === "true";
const [imageUri, setImageUri] = useState<string | null>(null);
Expand Down Expand Up @@ -114,6 +117,7 @@ const Page: React.FC<FileDetailProps> = () => {
/>
)}
{isRDFResource && data && <VcCard data={data} />}
<Loading isLoading={!!isMutatingFiles} />
<BottomSheetModal
enableDismissOnClose
ref={bottomSheetModalRef}
Expand All @@ -135,7 +139,7 @@ const Page: React.FC<FileDetailProps> = () => {
isRDFResource,
}}
onCloseModal={() => bottomSheetModalRef.current?.close()}
onDeleteSuccessfully={() => goBack()}
onDeleteSuccessfully={goBack}
onChangeSnapPoint={(snapHeight: number) =>
bottomSheetModalRef.current?.snapToPosition(snapHeight)
}
Expand Down

0 comments on commit 233020f

Please sign in to comment.