Skip to content

Commit 02ee133

Browse files
committed
fix: of-546 encounter header
1 parent f2bb78e commit 02ee133

File tree

3 files changed

+58
-33
lines changed

3 files changed

+58
-33
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { OPageHeader } from "@/components/OPageHeader/OPageHeader";
2+
import {
3+
EACTION_ENCOUNTERS,
4+
useEncountersContext,
5+
} from "@/context/EncountersContext";
6+
import { i18n, TR } from "@/localization/translate.service";
7+
import { getLocalValue, LOCAL_VALUE } from "@/services/storage.service";
8+
import * as Sentry from "@sentry/react-native";
9+
import * as React from "react";
10+
import { useEffect, useState } from "react";
11+
12+
export const OPageHeaderEncounters = () => {
13+
const { dispatch: dispatchEncounters } = useEncountersContext();
14+
15+
const [hasDoneEncounterWalkthrough, setHasDoneEncounterWalkthrough] =
16+
useState(true);
17+
18+
useEffect(() => {
19+
getLocalValue(LOCAL_VALUE.HAS_DONE_ENCOUNTER_WALKTHROUGH)
20+
.then((value) => {
21+
setHasDoneEncounterWalkthrough(value);
22+
})
23+
.catch((err: any) => {
24+
Sentry.captureException(err, {
25+
tags: {
26+
pageHeaderEncounters:
27+
"getLocalValue:hasDoneEncounterWalkthrough",
28+
},
29+
});
30+
});
31+
}, []);
32+
33+
return (
34+
<OPageHeader
35+
title={i18n.t(TR.encounters)}
36+
highlightHelpBtn={!hasDoneEncounterWalkthrough}
37+
onHelpPress={() => {
38+
dispatchEncounters({
39+
type: EACTION_ENCOUNTERS.SET_IS_WALKTHROUGH_RUNNING,
40+
payload: true,
41+
});
42+
}}
43+
/>
44+
);
45+
};

mobile/screens/main/MainScreenTabs.tsx

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { Color, Title } from "@/GlobalStyles";
22
import { OGoLiveToggle } from "@/components/OGoLiveToggle/OGoLiveToggle";
33
import { OPageHeader } from "@/components/OPageHeader/OPageHeader";
4-
import {
5-
EACTION_ENCOUNTERS,
6-
useEncountersContext,
7-
} from "@/context/EncountersContext";
4+
import { OPageHeaderEncounters } from "@/components/OPageHeader/OPageHeaderEncounters/OPageHeaderEncounters";
85
import { useNotifications } from "@/hooks/useNotifications";
96
import { TR, i18n } from "@/localization/translate.service";
107
import { MainTabs } from "@/screens/main/MainScreenTabs.navigator";
@@ -23,29 +20,16 @@ import ProfileSettings from "./ProfileSettings";
2320
export const MainScreenTabs = ({ navigation }: any) => {
2421
useNotifications(navigation);
2522

26-
const { state: encounterState, dispatch: dispatchEncounters } =
27-
useEncountersContext();
2823
const { tourKey: tourKeyFind, start: startTourFind } =
2924
useTourGuideController(TOURKEY.FIND);
30-
const { start: startTourEncounters } = useTourGuideController(
31-
TOURKEY.ENCOUNTERS,
32-
);
3325

3426
// @dev true by default to not unnecessarily distract user
3527
const [hasDoneFindWalkthrough, setHasDoneFindWalkthrough] = useState(true);
36-
const [hasDoneEncounterWalkthrough, setHasDoneEncounterWalkthrough] =
37-
useState(true);
3828

3929
useEffect(() => {
40-
const getValues = [
41-
getLocalValue(LOCAL_VALUE.HAS_DONE_FIND_WALKTHROUGH),
42-
getLocalValue(LOCAL_VALUE.HAS_DONE_ENCOUNTER_WALKTHROUGH),
43-
];
44-
45-
Promise.all(getValues)
46-
.then((vals: boolean[]) => {
47-
setHasDoneFindWalkthrough(vals[0]);
48-
setHasDoneEncounterWalkthrough(vals[1]);
30+
getLocalValue(LOCAL_VALUE.HAS_DONE_FIND_WALKTHROUGH)
31+
.then((value: boolean) => {
32+
setHasDoneFindWalkthrough(value);
4933
})
5034
.catch((err) => {
5135
Sentry.captureException(err, {
@@ -110,18 +94,7 @@ export const MainScreenTabs = ({ navigation }: any) => {
11094
component={EncounterScreenStack}
11195
options={{
11296
tabBarLabel: i18n.t(TR.encounters),
113-
headerLeft: () => (
114-
<OPageHeader
115-
title={i18n.t(TR.encounters)}
116-
highlightHelpBtn={!hasDoneEncounterWalkthrough}
117-
onHelpPress={() => {
118-
dispatchEncounters({
119-
type: EACTION_ENCOUNTERS.SET_IS_WALKTHROUGH_RUNNING,
120-
payload: true,
121-
});
122-
}}
123-
/>
124-
),
97+
headerLeft: () => <OPageHeaderEncounters />,
12598
// tabBarBadge:
12699
// unreadNotifications.length === 0
127100
// ? undefined

mobile/screens/main/ProfileView.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { UserPublicDTO } from "@/api/gen/src";
33
import { OBadgesOfUser } from "@/components/OBadge/OBadgesOfUser";
44
import { OPageContainer } from "@/components/OPageContainer/OPageContainer";
55
import { OPageHeader } from "@/components/OPageHeader/OPageHeader";
6+
import { OPageHeaderEncounters } from "@/components/OPageHeader/OPageHeaderEncounters/OPageHeaderEncounters";
67
import { TR, i18n } from "@/localization/translate.service";
78
import { EncounterStackParamList } from "@/screens/main/EncounterStack.navigator";
89
import { ROUTES } from "@/screens/routes";
@@ -63,11 +64,17 @@ const ProfileView = ({
6364

6465
useEffect(() => {
6566
// @dev overrides tab nav title
66-
navigation.getParent()?.setOptions({
67+
const parent = navigation.getParent();
68+
parent?.setOptions({
6769
headerLeft: () => (
6870
<OPageHeader title={`${user.firstName}, ${user.age}`} />
6971
),
7072
});
73+
return () => {
74+
parent?.setOptions({
75+
headerLeft: () => <OPageHeaderEncounters />,
76+
});
77+
};
7178
}); // empty dep array to run it only once
7279

7380
return (

0 commit comments

Comments
 (0)