Files
discord-decomp/modules/user_profile/WidgetStore.tsx
T
2026-11-01 12:12:55 +02:00

170 lines
5.2 KiB
TypeScript

// Metro module 5901 (f5902).
import UserStore from "../../stores/UserStore";
import UserProfileStore from "./UserProfileStore";
import Module589 from "../../_bundle/Module589";
import Module12 from "../../_bundle/Module12";
import Dispatcher from "../../Dispatcher";
let widgets = null;
let c3694_6 = null;
let c3694_7 = false;
let c3694_8 = {
suggestedGamesIds: [],
suggestedWishlistGamesIds: []
};
let c3694_9 = false;
let c3694_10 = false;
let c3694_11 = false;
class WidgetStore extends Module589.Store {
initialize() {
this.waitFor(UserStore);
}
getPendingWidgets() {
return widgets;
}
getSaveablePendingWidgets() {
return widgets != null ? widgets.filter((widget) => !widget.isDiscardable()) : null;
}
hasPendingChanges() {
return widgets !== null && (c3694_6 === null || !Module12.isEqual(widgets, c3694_6));
}
getWidgetUpdates() {
let r94;
let changedWidgets = this.getSaveablePendingWidgets();
if (changedWidgets != null && c3694_6 != null) {
const map2 = new Map(c3694_6.map((item) => [item.id, item]));
const map = new Map(changedWidgets.map((changedWidget) => [changedWidget.id, changedWidget]));
const changedWidgets2 = [];
const removedWidgets = [];
for (const item of map) {
const [r52, r53] = item;
const r55 = map2.get(r52);
if (!(r55 != null && r53.isEqual(r55))) {
changedWidgets2.push(r53);
}
}
for (const item2 of map2) {
const [r71, r72] = item2;
if (!map.has(r71)) {
removedWidgets.push(r72);
}
}
const length = changedWidgets.length;
let r80 = 0;
const r81 = 0 < length;
let hasOrderChanges = false;
if (r81) {
do {
const r84 = changedWidgets[r80];
const r85 = r84 == null;
const r86 = r80;
const r87 = r85 ? void 0 : r84.id;
const id = c3694_6[r86]?.id;
hasOrderChanges = true;
if (r87 !== id) {
break;
}
const r92 = r86 + 1;
r94 = r92 < changedWidgets.length;
r80 = r92;
hasOrderChanges = false;
} while (r94);
}
return {
changedWidgets: changedWidgets2,
removedWidgets,
hasOrderChanges
};
}
if (changedWidgets == null) {
changedWidgets = [];
}
return {
changedWidgets,
removedWidgets: [],
hasOrderChanges: false
};
}
getChangedWidgets() {
return this.getWidgetUpdates().changedWidgets;
}
getRemovedWidgets() {
return this.getWidgetUpdates().removedWidgets;
}
hasUnsavedChanges() {
const widgetUpdates = this.getWidgetUpdates();
const { changedWidgets, removedWidgets, hasOrderChanges } = widgetUpdates;
return changedWidgets.length > 0 || removedWidgets.length > 0 || hasOrderChanges;
}
canSaveChanges() {
const saveablePendingWidgets = this.getSaveablePendingWidgets();
return saveablePendingWidgets != null && saveablePendingWidgets.every((saveablePendingWidget) => saveablePendingWidget.isValid());
}
get isSubmitting() {
return c3694_7;
}
get suggestedFetchError() {
return c3694_9;
}
get suggestedFetchIsLoading() {
return c3694_10;
}
get suggestedFetchAttempted() {
return c3694_11;
}
get suggestedGameIds() {
return c3694_8;
}
}
const widgetStore = new WidgetStore(Dispatcher, {
WIDGET_PENDING_SET: function handleSetPendingWidgets(a0) {
widgets = a0.widgets;
if (c3694_6 === null) {
const currentUser = UserStore.getCurrentUser();
if (currentUser != null) {
let r13 = UserProfileStore.getUserProfile(currentUser.id)?.widgets;
if (r13 == null) {
r13 = [];
}
c3694_6 = r13;
}
}
},
WIDGET_PENDING_SAVE_START: function handleSavePendingWidgetsStart() {
c3694_7 = true;
},
WIDGET_PENDING_SAVE_SUCCESS: function handleSavePendingWidgetsSuccess() {
c3694_7 = false;
if (widgets !== null) {
c3694_6 = null;
widgets = null;
}
},
WIDGET_PENDING_SAVE_FAILURE: function handleSavePendingWidgetsFailure() {
c3694_7 = false;
},
WIDGET_SUGGESTED_FETCH_SUCCESS: function handleSetSuggestedGameIds({ suggestedGamesIds, suggestedWishlistGamesIds }) {
c3694_8.suggestedGamesIds = suggestedGamesIds;
c3694_8.suggestedWishlistGamesIds = suggestedWishlistGamesIds;
c3694_10 = false;
c3694_9 = false;
},
WIDGET_SUGGESTED_FETCH_FAILURE: function handleSetSuggestedFetchFailure() {
c3694_9 = true;
c3694_10 = false;
},
WIDGET_SUGGESTED_FETCH_START: function handleSetSuggestedFetchStart() {
c3694_10 = true;
c3694_9 = false;
c3694_11 = true;
},
WIDGET_PENDING_CLEAR: function handleClearPendingWidgets() {
widgets = null;
c3694_6 = null;
},
WIDGET_SUGGESTED_REMOVE_GAME: function handleRemoveApplicationIdFromSuggestedGames({ applicationId }) {
c3694_8.suggestedGamesIds = c3694_8.suggestedGamesIds.filter((suggestedGamesId) => suggestedGamesId !== applicationId);
c3694_8.suggestedWishlistGamesIds = c3694_8.suggestedWishlistGamesIds.filter((suggestedWishlistGamesId) => suggestedWishlistGamesId !== applicationId);
}
});
export default widgetStore;