167 lines
5.6 KiB
TypeScript
167 lines
5.6 KiB
TypeScript
// Metro module 15283 (f15284).
|
|
import _slicedToArray from "../../_bundle/_slicedToArray";
|
|
import { useRef, useState, useEffect, useCallback } from "react";
|
|
import RecentMentionsStore from "../inbox/RecentMentionsStore";
|
|
import NotificationCenterItemsStore from "./NotificationCenterItemsStore";
|
|
import NotificationCenterStore from "./NotificationCenterStore";
|
|
import { ReadStateTypes } from "../read_states/ReadStateConstants";
|
|
import { useStateFromStores, useStateFromStoresObject } from "../../_bundle/Module589";
|
|
import { setNotificationCenterActive, resetNotificationCenter, fetchNotificationCenterItems } from "./NotificationCenterItemsActions";
|
|
import { ackUserFeature } from "../../actions/ReadStateActionCreators";
|
|
import useGetIsMounted from "../../hooks/useGetIsMounted";
|
|
let env10860 = {};
|
|
export const PAGE_SIZE_WITH_MENTIONS = 8;
|
|
export const PAGE_SIZE = 20;
|
|
export function useNotificationCenterItemsLoader(a0) {
|
|
let env21842 = {
|
|
$parent: env10860
|
|
};
|
|
const isFocused = a0.isFocused;
|
|
env21842[0] = isFocused;
|
|
const navigatedAway = a0.navigatedAway;
|
|
env21842[1] = navigatedAway;
|
|
const isDesktop = a0.isDesktop;
|
|
env21842[2] = isDesktop;
|
|
let withMentions = a0.withMentions;
|
|
if (withMentions === void 0) {
|
|
withMentions = false;
|
|
}
|
|
let c21843_0;
|
|
env21842[3] = withMentions;
|
|
const initialPageSize = a0.initialPageSize;
|
|
env21842[4] = initialPageSize;
|
|
env21842[5] = void 0;
|
|
env21842[6] = void 0;
|
|
env21842[7] = void 0;
|
|
env21842[8] = void 0;
|
|
env21842[9] = void 0;
|
|
env21842[10] = void 0;
|
|
env21842[11] = void 0;
|
|
env21842[12] = void 0;
|
|
env21842[13] = void 0;
|
|
env21842[14] = void 0;
|
|
env21842[15] = void 0;
|
|
const stateFromStores = useStateFromStores([NotificationCenterStore], () => NotificationCenterStore.shouldReload());
|
|
env21842[5] = stateFromStores;
|
|
env21842[6] = useRef(false);
|
|
const r33 = _slicedToArray(useState(false), 2);
|
|
const loadingMore = r33[0];
|
|
env21842[7] = r33[1];
|
|
const stateFromStoresObject = useStateFromStoresObject([NotificationCenterItemsStore], () => ({
|
|
initialized: NotificationCenterItemsStore.initialized,
|
|
loading: NotificationCenterItemsStore.loading,
|
|
items: NotificationCenterItemsStore.items,
|
|
hasMore: NotificationCenterItemsStore.hasMore,
|
|
cursor: NotificationCenterItemsStore.cursor,
|
|
errored: NotificationCenterItemsStore.errored
|
|
}));
|
|
const initialized = stateFromStoresObject.initialized;
|
|
env21842[8] = initialized;
|
|
const { loading, items } = stateFromStoresObject;
|
|
env21842[9] = items;
|
|
const hasMore = stateFromStoresObject.hasMore;
|
|
env21842[10] = hasMore;
|
|
const cursor = stateFromStoresObject.cursor;
|
|
env21842[11] = cursor;
|
|
const errored = stateFromStoresObject.errored;
|
|
env21842[12] = errored;
|
|
const stateFromStoresObject2 = useStateFromStoresObject([RecentMentionsStore], () => ({
|
|
everyoneFilter: RecentMentionsStore.everyoneFilter,
|
|
roleFilter: RecentMentionsStore.roleFilter
|
|
}));
|
|
const roleFilter = stateFromStoresObject2.roleFilter;
|
|
env21842[13] = roleFilter;
|
|
const everyoneFilter = stateFromStoresObject2.everyoneFilter;
|
|
env21842[14] = everyoneFilter;
|
|
useEffect(() => {
|
|
setNotificationCenterActive(true);
|
|
return () => setNotificationCenterActive(false);
|
|
}, []);
|
|
useEffect(() => {
|
|
if (env21842[8] && env21842[0]) {
|
|
ackUserFeature(ReadStateTypes.NOTIFICATION_CENTER);
|
|
}
|
|
}, [isFocused, initialized]);
|
|
const getIsMounted = useGetIsMounted();
|
|
env21842[15] = getIsMounted;
|
|
useEffect(() => () => {
|
|
if (env21842[2]) {
|
|
const r17 = (0, env21842[15])();
|
|
if (r17 ? !r17 : env21842[12] || env21842[9].length > 100) {
|
|
resetNotificationCenter();
|
|
}
|
|
} else if (env21842[1] && env21842[9].length > 100) {
|
|
resetNotificationCenter();
|
|
}
|
|
}, [navigatedAway, items, isDesktop, getIsMounted, errored]);
|
|
useEffect(() => {
|
|
const r4 = env21842[8];
|
|
if (r4 ? env21842[5] && env21842[0] : !r4) {
|
|
let limit = env21842[4];
|
|
if (limit == null) {
|
|
limit = env21842[3] ? 8 : 20;
|
|
}
|
|
fetchNotificationCenterItems({
|
|
limit,
|
|
with_mentions: env21842[3],
|
|
roles_filter: env21842[13],
|
|
everyone_filter: env21842[14]
|
|
});
|
|
}
|
|
}, [initialized, stateFromStores, isFocused, withMentions, roleFilter, everyoneFilter, initialPageSize]);
|
|
c21843_0 = void 0;
|
|
c21843_0 = async (c30857_0) => {
|
|
let r47;
|
|
let c30857_1;
|
|
L26: {
|
|
c30857_1 = void 0;
|
|
const r10 = env21842[6];
|
|
if (r10.current || !env21842[8] || !env21842[10] || env21842[11] == null || (c30857_0 ? !c30857_0 : env21842[12])) {
|
|
break L26;
|
|
}
|
|
r10.current = true;
|
|
(0, env21842[7])(true);
|
|
const after = env21842[11];
|
|
const with_mentions = env21842[3];
|
|
const r42 = {
|
|
after,
|
|
with_mentions,
|
|
roles_filter: env21842[13],
|
|
everyone_filter: env21842[14],
|
|
limit: null
|
|
};
|
|
const limit = 20;
|
|
if (!with_mentions) {
|
|
r42.limit = limit;
|
|
r47 = fetchNotificationCenterItems(r42, () => {
|
|
env21842[6].current = false;
|
|
});
|
|
} else {
|
|
r42.limit = 8;
|
|
r47 = fetchNotificationCenterItems(r42, () => {
|
|
env21842[6].current = false;
|
|
});
|
|
}
|
|
await r47;
|
|
(0, env21842[7])(false);
|
|
return void 0;
|
|
}
|
|
};
|
|
return {
|
|
initialized,
|
|
loading,
|
|
items,
|
|
hasMore,
|
|
loadMore: useCallback(function() {
|
|
return c21843_0.apply(this, arguments);
|
|
}, [initialized, hasMore, cursor, errored, withMentions, roleFilter, everyoneFilter]),
|
|
loadingMore,
|
|
setReadNotifItemToAcked: function setReadNotifItemToAcked(a0) {
|
|
if (!a0.acked) {
|
|
a0.acked = true;
|
|
}
|
|
},
|
|
errored
|
|
};
|
|
}
|