From 779630ebd5e1b3a18794dfea5307771f67fdf583 Mon Sep 17 00:00:00 2001 From: "dmitrii.pichenikin" Date: Mon, 16 Mar 2026 15:01:12 +0300 Subject: [PATCH] LP-5723: back button logic fix --- webapp/src/actions/actions.ts | 14 +++++++++++--- webapp/src/components/rhs/badge_details.tsx | 5 +++-- webapp/src/components/rhs/index.tsx | 4 +++- webapp/src/constants.ts | 1 + webapp/src/reducers/index.ts | 10 ++++++++++ webapp/src/selectors/index.ts | 7 +++++++ webapp/src/types/general.ts | 1 + 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/webapp/src/actions/actions.ts b/webapp/src/actions/actions.ts index a0cb756..3815b54 100644 --- a/webapp/src/actions/actions.ts +++ b/webapp/src/actions/actions.ts @@ -3,6 +3,7 @@ import {AnyAction, Dispatch} from 'redux'; import ActionTypes from 'action_types/'; import {BadgeDetails, BadgeID, BadgeTypeDefinition} from 'types/badges'; import {GrantModalData, RHSState, SubscriptionModalData} from 'types/general'; +import {id as pluginId} from '../manifest'; /** * Stores`showRHSPlugin` action returned by @@ -30,9 +31,16 @@ export function setRHSBadge(badgeID: BadgeID | null) { } export function setRHSView(view: RHSState) { - return { - type: ActionTypes.RECEIVED_RHS_VIEW, - data: view, + return (dispatch: Dispatch, getState: () => any) => { + const state = getState(); + const pluginState = state['plugins-' + pluginId]; + const currentView = pluginState?.rhsView; + dispatch({ + type: ActionTypes.RECEIVED_RHS_VIEW, + data: view, + prevView: currentView, + }); + return {data: true}; }; } diff --git a/webapp/src/components/rhs/badge_details.tsx b/webapp/src/components/rhs/badge_details.tsx index 177df92..d723768 100644 --- a/webapp/src/components/rhs/badge_details.tsx +++ b/webapp/src/components/rhs/badge_details.tsx @@ -8,7 +8,7 @@ import {BadgeDetails, BadgeID} from '../../types/badges'; import Client from '../../client/api'; import {RHSState} from '../../types/general'; -import {IMAGE_TYPE_EMOJI, RHS_STATE_ALL, RHS_STATE_MY, RHS_STATE_OTHER} from '../../constants'; +import {IMAGE_TYPE_EMOJI, RHS_STATE_MY, RHS_STATE_OTHER} from '../../constants'; import BadgeImage from '../badge_image/badge_image'; import {markdown} from 'utils/markdown'; @@ -23,6 +23,7 @@ import './badge_details.scss'; type Props = { badgeID: BadgeID | null; currentUserID: string; + prevView: RHSState; actions: { setRHSView: (view: RHSState) => void; setRHSUser: (user: string | null) => void; @@ -128,7 +129,7 @@ class BadgeDetailsComponent extends React.PureComponent {
{ const dispatch = useDispatch(); const currentView = useSelector(getRHSView); + const prevView = useSelector(getPrevRHSView); const currentBadge = useSelector(getRHSBadge); const currentUserID = useSelector(getRHSUser); const filterTypeId = useSelector(getRHSTypeId); @@ -159,6 +160,7 @@ const RHS: React.FC = () => { dispatch(setRHSView(view)), setRHSUser: (user: string | null) => dispatch(setRHSUser(user)), diff --git a/webapp/src/constants.ts b/webapp/src/constants.ts index dbc28d3..564bf35 100644 --- a/webapp/src/constants.ts +++ b/webapp/src/constants.ts @@ -14,6 +14,7 @@ export const RHS_STATE_TYPE_BADGES: RHSState = 'type_badges'; export const initialState: PluginState = { showRHS: null, rhsView: RHS_STATE_MY, + prevRhsView: RHS_STATE_MY, rhsBadge: null, rhsUser: null, rhsTypeId: null, diff --git a/webapp/src/reducers/index.ts b/webapp/src/reducers/index.ts index 02fda19..7d84141 100644 --- a/webapp/src/reducers/index.ts +++ b/webapp/src/reducers/index.ts @@ -23,6 +23,15 @@ function rhsView(state = RHS_STATE_MY, action: GenericAction) { } } +function prevRhsView(state = RHS_STATE_MY, action: GenericAction) { + switch (action.type) { + case ActionTypes.RECEIVED_RHS_VIEW: + return action.prevView || state; + default: + return state; + } +} + function rhsUser(state = null, action: GenericAction) { switch (action.type) { case ActionTypes.RECEIVED_RHS_USER: @@ -128,6 +137,7 @@ function subscriptionModalData(state = null, action: GenericAction) { export default combineReducers({ showRHS, rhsView, + prevRhsView, rhsUser, rhsBadge, rhsTypeId, diff --git a/webapp/src/selectors/index.ts b/webapp/src/selectors/index.ts index 3cfb8fb..34a129a 100644 --- a/webapp/src/selectors/index.ts +++ b/webapp/src/selectors/index.ts @@ -30,6 +30,13 @@ export const getRHSView = createSelector( }, ); +export const getPrevRHSView = createSelector( + getPluginState, + (state) => { + return state.prevRhsView; + }, +); + export const getRHSUser = createSelector( getPluginState, (state) => { diff --git a/webapp/src/types/general.ts b/webapp/src/types/general.ts index ab36aa8..0b3cdea 100644 --- a/webapp/src/types/general.ts +++ b/webapp/src/types/general.ts @@ -14,6 +14,7 @@ export type SubscriptionModalData = { export type PluginState = { showRHS: (() => void)| null; rhsView: RHSState; + prevRhsView: RHSState; rhsUser: string | null; rhsBadge: BadgeID | null; rhsTypeId: number | null;