From 351030d0a71b4eabdbbded6e0c5c9715c7a468eb Mon Sep 17 00:00:00 2001 From: Thomas Wallner Date: Fri, 28 Oct 2022 17:43:43 +0200 Subject: [PATCH 1/2] refactor(history): showing user latest added record on History screen when interaction is done --- src/hooks/interactions/useAuthSubmit.ts | 7 ++++--- src/hooks/interactions/useAuthzSubmit.ts | 6 +++--- src/screens/LoggedIn/History/RecordItemsList.tsx | 16 +++++++++++++++- src/screens/LoggedIn/History/index.tsx | 8 +++++++- src/screens/LoggedIn/History/types.ts | 1 + src/screens/LoggedIn/MainTabs.tsx | 2 +- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/hooks/interactions/useAuthSubmit.ts b/src/hooks/interactions/useAuthSubmit.ts index 0a03d0f0e..d8042f056 100644 --- a/src/hooks/interactions/useAuthSubmit.ts +++ b/src/hooks/interactions/useAuthSubmit.ts @@ -2,19 +2,20 @@ import { useInteraction } from './handlers' import { useCompleteInteraction } from './useCompleteInteraction' import { useAgent } from '../sdk' import { ScreenNames } from '~/types/screens' +import { useRedirect } from '../navigation' +import History from '~/screens/LoggedIn/History' const useAuthSubmit = () => { const getInteraction = useInteraction() const agent = useAgent() + const redirect = useRedirect() const { completeInteraction } = useCompleteInteraction(async () => { const interaction = await getInteraction() const authResponse = await interaction.createAuthenticationResponse() await agent.processJWT(authResponse) await interaction.send(authResponse) - return { - screenToNavigate: ScreenNames.History, - } + return redirect(ScreenNames.History, { id: interaction.id }) }) return completeInteraction diff --git a/src/hooks/interactions/useAuthzSubmit.ts b/src/hooks/interactions/useAuthzSubmit.ts index e165ffae5..875d68336 100644 --- a/src/hooks/interactions/useAuthzSubmit.ts +++ b/src/hooks/interactions/useAuthzSubmit.ts @@ -2,19 +2,19 @@ import { useInteraction } from './handlers' import { useCompleteInteraction } from './useCompleteInteraction' import { useAgent } from '../sdk' import { ScreenNames } from '~/types/screens' +import { useRedirect } from '../navigation' const useAuthzSubmit = () => { const getInteraction = useInteraction() const agent = useAgent() + const redirect = useRedirect() const { completeInteraction } = useCompleteInteraction(async () => { const interaction = await getInteraction() const authzResponse = await interaction.createAuthorizationResponse() await agent.processJWT(authzResponse) await interaction.send(authzResponse) - return { - screenToNavigate: ScreenNames.History, - } + return redirect(ScreenNames.History, { id: interaction.id }) }) return completeInteraction diff --git a/src/screens/LoggedIn/History/RecordItemsList.tsx b/src/screens/LoggedIn/History/RecordItemsList.tsx index 6ae218393..4d48fa1d7 100644 --- a/src/screens/LoggedIn/History/RecordItemsList.tsx +++ b/src/screens/LoggedIn/History/RecordItemsList.tsx @@ -21,11 +21,22 @@ import { LoaderAnimation } from '~/components/LoaderAnimation/LoaderAnimation' const ITEMS_PER_PAGE = 5 -const RecordItemsList: React.FC = ({ id, flows }) => { +const RecordItemsList: React.FC = ({ + id, + itemId, + flows, +}) => { const { t } = useTranslation() const sectionListRef = useRef(null) const { updateActiveSection } = useRecord() + useEffect(() => { + itemId && setFocusedItem(itemId) + return () => { + setFocusedItem(null) + } + }, [itemId]) + const [activeSection, setActiveSection] = useState('') const [interactions, setInteractions] = useState([]) const [page, setPage] = useState(0) @@ -52,12 +63,14 @@ const RecordItemsList: React.FC = ({ id, flows }) => { useInteractionCreate((interaction) => { if (shouldUpdateRecords(interaction, flows)) { + setFocusedItem(interaction.id) setInteractions((prev) => createInteractionRecord(interaction, prev)) } }) useInteractionUpdate((interaction) => { if (shouldUpdateRecords(interaction, flows)) { + setFocusedItem(interaction.id) setInteractions((prev) => updateInteractionRecord(interaction, prev)) } }) @@ -75,6 +88,7 @@ const RecordItemsList: React.FC = ({ id, flows }) => { useEffect(() => { getInteractionTokens(ITEMS_PER_PAGE, 0, flows) .then((tokens) => { + tokens.length && setFocusedItem(tokens[0].id) setTimeout(() => setLoaderType(LoaderTypes.empty), 200) setInteractions(tokens) }) diff --git a/src/screens/LoggedIn/History/index.tsx b/src/screens/LoggedIn/History/index.tsx index 8ce886523..61e6bfa2e 100644 --- a/src/screens/LoggedIn/History/index.tsx +++ b/src/screens/LoggedIn/History/index.tsx @@ -1,10 +1,13 @@ import { FlowType } from '@jolocom/sdk' +import { RouteProp, useRoute } from '@react-navigation/native' import React from 'react' import ScreenContainer from '~/components/ScreenContainer' import TabsContainer from '~/components/Tabs/Container' import Tabs from '~/components/Tabs/Tabs' import useTranslation from '~/hooks/useTranslation' +import { ScreenNames } from '~/types/screens' +import { MainTabsParamList } from '../MainTabs' import Record from './Record' export enum RecordTypes { @@ -15,6 +18,9 @@ export enum RecordTypes { const History = () => { const { t } = useTranslation() + const itemId = + useRoute>().params?.id + const SUBTABS = [ { id: 'all', value: t('History.allTab') }, { id: 'shared', value: t('History.sharedTab') }, @@ -43,7 +49,7 @@ const History = () => { {/* ItemsList should have a param type: should be added once there is a support for passing multiple interaction types to support all subtab usecase */} - + Date: Mon, 7 Nov 2022 09:57:30 +0100 Subject: [PATCH 2/2] refactor(recordlistitem): adding id as a route param to the CredentialShare flow --- src/hooks/interactions/useAuthSubmit.ts | 1 - src/hooks/interactions/useCredentialShareSubmit.ts | 9 ++++++--- src/screens/LoggedIn/History/RecordItemsList.tsx | 2 -- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hooks/interactions/useAuthSubmit.ts b/src/hooks/interactions/useAuthSubmit.ts index d8042f056..7c1652c4d 100644 --- a/src/hooks/interactions/useAuthSubmit.ts +++ b/src/hooks/interactions/useAuthSubmit.ts @@ -3,7 +3,6 @@ import { useCompleteInteraction } from './useCompleteInteraction' import { useAgent } from '../sdk' import { ScreenNames } from '~/types/screens' import { useRedirect } from '../navigation' -import History from '~/screens/LoggedIn/History' const useAuthSubmit = () => { const getInteraction = useInteraction() diff --git a/src/hooks/interactions/useCredentialShareSubmit.ts b/src/hooks/interactions/useCredentialShareSubmit.ts index 08203cb4c..0ab225ecf 100644 --- a/src/hooks/interactions/useCredentialShareSubmit.ts +++ b/src/hooks/interactions/useCredentialShareSubmit.ts @@ -1,15 +1,18 @@ import { useCredentialShareFlow } from './useCredentialShareFlow' import { useCompleteInteraction } from './useCompleteInteraction' import { ScreenNames } from '~/types/screens' +import { useInteraction } from './handlers' +import { useRedirect } from '../navigation' const useCredentialShareSubmit = () => { + const getInteraction = useInteraction() const { assembleShareResponseToken } = useCredentialShareFlow() + const redirect = useRedirect() const { completeInteraction } = useCompleteInteraction(async () => { + const interaction = await getInteraction() await assembleShareResponseToken() - return { - screenToNavigate: ScreenNames.History, - } + return redirect(ScreenNames.History, { id: interaction.id }) }) return completeInteraction diff --git a/src/screens/LoggedIn/History/RecordItemsList.tsx b/src/screens/LoggedIn/History/RecordItemsList.tsx index 4d48fa1d7..7951e8a18 100644 --- a/src/screens/LoggedIn/History/RecordItemsList.tsx +++ b/src/screens/LoggedIn/History/RecordItemsList.tsx @@ -63,14 +63,12 @@ const RecordItemsList: React.FC = ({ useInteractionCreate((interaction) => { if (shouldUpdateRecords(interaction, flows)) { - setFocusedItem(interaction.id) setInteractions((prev) => createInteractionRecord(interaction, prev)) } }) useInteractionUpdate((interaction) => { if (shouldUpdateRecords(interaction, flows)) { - setFocusedItem(interaction.id) setInteractions((prev) => updateInteractionRecord(interaction, prev)) } })