Skip to content

Commit

Permalink
adding the ability to force refresh fblo
Browse files Browse the repository at this point in the history
  • Loading branch information
IDCs committed Nov 28, 2023
1 parent 36eddf1 commit b18078a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/extensions/file_based_loadorder/actions/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import createAction from '../../../actions/safeCreateAction';

// This is a hack to force the load order to update.
// It's absolutely mandatory to ensure this is
// dispatched sparingly, as it will cause a full re-rendering
// of the load order page EACH time.
export const setFBForceUpdate =
createAction('SET_FB_FORCE_UPDATE', (profileId: string) => ({ profileId })) as any;
2 changes: 2 additions & 0 deletions src/extensions/file_based_loadorder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { generate, Interface, parser } from './collections/loadOrder';
import FileBasedLoadOrderPage from './views/FileBasedLoadOrderPage';

import { modLoadOrderReducer } from './reducers/loadOrder';
import { sessionReducer } from './reducers/session';

import * as types from '../../types/api';
import * as util from '../../util/api';
Expand Down Expand Up @@ -195,6 +196,7 @@ function genDidPurge(api: types.IExtensionApi) {

export default function init(context: IExtensionContext) {
context.registerReducer(['persistent', 'loadOrder'], modLoadOrderReducer);
context.registerReducer(['session', 'fblo', 'refresh'], sessionReducer);

context.registerMainPage('sort-none', 'Load Order', FileBasedLoadOrderPage, {
id: 'file-based-loadorder',
Expand Down
17 changes: 17 additions & 0 deletions src/extensions/file_based_loadorder/reducers/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IReducerSpec } from '../../../types/IExtensionContext';
import { setSafe } from '../../../util/storeHelper';

import { generate } from 'shortid';

import * as actions from '../actions/session';

export const sessionReducer: IReducerSpec = {
reducers: {
[actions.setFBForceUpdate as any]: (state, payload) => {
const { profileId } = payload;
const uId = generate();
return setSafe(state, [profileId], uId);
}
},
defaults: {},
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface IBaseState {
loading: boolean;
updating: boolean;
validationError: LoadOrderValidationError;
currentRefreshId: string;
}

export interface IBaseProps {
Expand All @@ -42,6 +43,10 @@ interface IConnectedProps {

// Does the user need to deploy ?
needToDeploy: boolean;

// The refresh id for the current profile
// (used to force a refresh of the list)
refreshId: string;
}

interface IActionProps {
Expand All @@ -61,6 +66,7 @@ class FileBasedLoadOrderPage extends ComponentEx<IProps, IComponentState> {
loading: true,
updating: false,
validationError: undefined,
currentRefreshId: '',
});

this.mStaticButtons = [
Expand Down Expand Up @@ -104,6 +110,14 @@ class FileBasedLoadOrderPage extends ComponentEx<IProps, IComponentState> {
];
}

public UNSAFE_componentWillReceiveProps(newProps: IProps) {
// Zuckerberg isn't going to like this...
if (this.state.currentRefreshId !== newProps.refreshId) {
this.onRefreshList();
this.nextState.currentRefreshId = newProps.refreshId;
}
}

public componentDidMount() {
const { onSetOrder, onStartUp, profile } = this.props;
onStartUp(profile?.gameId)
Expand Down Expand Up @@ -268,6 +282,7 @@ function mapStateToProps(state: types.IState, ownProps: IProps): IConnectedProps
loadOrder,
profile,
needToDeploy: selectors.needToDeploy(state),
refreshId: util.getSafe(state, ['session', 'fblo', 'refresh', profile?.id], ''),
};
}

Expand Down

0 comments on commit b18078a

Please sign in to comment.