295 lines
13 KiB
TypeScript
295 lines
13 KiB
TypeScript
// Metro module 14972 (f14973).
|
|
import * as Module19 from "react";
|
|
import { useRef, useCallback, useMemo } from "react";
|
|
import LurkingStore from "../../lurker_mode/LurkingStore";
|
|
import { getGuildIconSource, getGuildIconURL } from "../../../records/GuildRecord";
|
|
import GuildAvailabilityStore from "../../../stores/GuildAvailabilityStore";
|
|
import GuildReadStateStore from "../../../stores/GuildReadStateStore";
|
|
import GuildStore from "../../../stores/GuildStore";
|
|
import SelectedGuildStore from "../../../stores/SelectedGuildStore";
|
|
import SortedGuildStore from "../../../stores/SortedGuildStore";
|
|
import { useItemDragState } from "./GuildsBarDnDStore";
|
|
import { TRANSITION_PHYSICS } from "./GuildsBarConstants";
|
|
import { AnalyticEvents } from "../../../Constants";
|
|
import { makeMutable, useSharedValue } from "../../reanimated/ReanimatedRexport";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import Module712 from "../../../_bundle/Module712";
|
|
import MobileVisualRefreshExperiment from "../../themes/experiments/MobileVisualRefreshExperiment";
|
|
import { useToken } from "../../../design/tokens/native/useToken";
|
|
import GuildsBarAnimatedItemWrapper, { useGuildsBarAnimatedWrapperStyles } from "./GuildsBarAnimatedItemWrapper";
|
|
import { MobileHomeDrawerExperiment } from "../../home_drawer/native/HomeDrawerExperiment";
|
|
import { useDrawerOpen } from "../../home_drawer/native/useDrawerState";
|
|
import HomeDrawerGuildRow, { HomeDrawerActiveHook } from "../../home_drawer/native/HomeDrawerGuildRow";
|
|
import { useStateFromStoresObject, useStateFromStores } from "../../../_bundle/Module589";
|
|
import GuildIcon, { ImageSizes, GuildIconSizes } from "../../guild/native/GuildIcon";
|
|
import isGuildsBarGuildDataEqual from "./utils/isGuildsBarGuildDataEqual";
|
|
import useGuildsBarBadges from "./hooks/useGuildsBarBadges";
|
|
import AlertActionCreators from "../../../actions/AlertActionCreators";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
|
|
import { trackGuildIconClicked } from "../../lurker_mode/LurkerPreviewAnalytics";
|
|
import transitionGuildsBarToGuildOrOpenSelectedChannel from "./utils/transitionGuildsBarToGuildOrOpenSelectedChannel";
|
|
import { getIsScreenReaderEnabled } from "../../a11y/native/useIsScreenReaderEnabled.native";
|
|
import getGuildsBarGuildMenuItems from "./utils/getGuildsBarGuildMenuItems";
|
|
import { showContextMenu, hideContextMenu } from "../../../design/components/ContextMenu/native/ContextMenuState.native";
|
|
import usePreloadedGuildAsset from "./hooks/usePreloadedGuildAsset";
|
|
import getGuildsBarGuildAccessibilityActions from "./utils/getGuildsBarGuildAccessibilityActions";
|
|
import * as _spring from "../../../design/animation/reanimated/spring/spring";
|
|
import FastImage from "../../../components_native/common/FastImage";
|
|
import Module14998 from "../../../_bundle/Module14998";
|
|
const state = {
|
|
pan: makeMutable(-1),
|
|
itemMeasurements: makeMutable([]),
|
|
activeIndex: makeMutable(-1)
|
|
};
|
|
const useStyles = createStyles({
|
|
guildIcon: {
|
|
width: Module712.modules.mobile.GUILD_BAR_ITEM_SIZE,
|
|
height: Module712.modules.mobile.GUILD_BAR_ITEM_SIZE
|
|
}
|
|
});
|
|
const __initData = {
|
|
code: "function GuildsBarGuildTsx1(values){const{dragDropInProgress,sharedId,guildId,isDragTarget,withSpring,TRANSITION_PHYSICS}=this.__closure;var _guildId;const shouldAnimate=dragDropInProgress.get()&&sharedId.get()===guildId&&!isDragTarget;sharedId.set((_guildId=guildId)!==null&&_guildId!==void 0?_guildId:null);return{animations:{originY:shouldAnimate?withSpring(values.targetOriginY,TRANSITION_PHYSICS,'animate-always'):values.targetOriginY,height:shouldAnimate?withSpring(values.targetHeight,TRANSITION_PHYSICS,'animate-always'):values.targetHeight},initialValues:{originY:values.currentOriginY,height:values.currentHeight}};}"
|
|
};
|
|
const r79 = Module19.memo(function GuildsBarGuild(props) {
|
|
let selected, isUnavailable, mentionCount, unread, isLurking, guildName, mediaState, isDragTarget, dragDropInProgress, stateFromStores, sharedValue;
|
|
const guildId = props.guildId;
|
|
let isDragPreview = props.isDragPreview;
|
|
if (isDragPreview === void 0) {
|
|
isDragPreview = false;
|
|
}
|
|
let hideExpandedChildren = props.hideExpandedChildren;
|
|
if (hideExpandedChildren === void 0) {
|
|
hideExpandedChildren = false;
|
|
}
|
|
selected = void 0;
|
|
isUnavailable = void 0;
|
|
mentionCount = void 0;
|
|
unread = void 0;
|
|
isLurking = void 0;
|
|
guildName = void 0;
|
|
mediaState = void 0;
|
|
isDragTarget = void 0;
|
|
dragDropInProgress = void 0;
|
|
stateFromStores = void 0;
|
|
sharedValue = void 0;
|
|
const r31 = MobileVisualRefreshExperiment("GuildsBarGuild");
|
|
const styles = useStyles();
|
|
const token = useToken(Module712.modules.mobile.GUILD_BAR_ITEM_SIZE);
|
|
const styles2 = useGuildsBarAnimatedWrapperStyles({
|
|
disableSelectedColor: true,
|
|
disableBGColor: true
|
|
});
|
|
const enableHome = MobileHomeDrawerExperiment.useConfig({
|
|
location: "guilds"
|
|
}).enableHome;
|
|
const drawerOpen = useDrawerOpen(enableHome);
|
|
const ref = useRef(HomeDrawerActiveHook.NONE);
|
|
const callback = useCallback((a0) => {
|
|
ref.current = a0;
|
|
}, []);
|
|
const stateFromStoresObject = useStateFromStoresObject([SelectedGuildStore, GuildAvailabilityStore, GuildReadStateStore, LurkingStore], () => ({
|
|
selected: SelectedGuildStore.getGuildId() === guildId,
|
|
isUnavailable: GuildAvailabilityStore.isUnavailable(guildId),
|
|
unread: GuildReadStateStore.hasUnread(guildId),
|
|
mentionCount: GuildReadStateStore.getMentionCount(guildId),
|
|
isMentionLowImportance: GuildReadStateStore.getIsMentionLowImportance(guildId),
|
|
isLurking: LurkingStore.isLurking(guildId)
|
|
}), [guildId]);
|
|
selected = stateFromStoresObject.selected;
|
|
isUnavailable = stateFromStoresObject.isUnavailable;
|
|
mentionCount = stateFromStoresObject.mentionCount;
|
|
unread = stateFromStoresObject.unread;
|
|
const isMentionLowImportance = stateFromStoresObject.isMentionLowImportance;
|
|
isLurking = stateFromStoresObject.isLurking;
|
|
const stateFromStores2 = useStateFromStores([GuildStore], () => {
|
|
const guild = GuildStore.getGuild(guildId);
|
|
const icon = guild != null ? getGuildIconURL(guild, token, selected) : void 0;
|
|
return {
|
|
guildName: guild?.name,
|
|
icon,
|
|
asset: icon != null ? guild != null ? getGuildIconSource(guild, ImageSizes[GuildIconSizes.LARGE], selected) : void 0 : void 0
|
|
};
|
|
}, [guildId, token, selected], isGuildsBarGuildDataEqual);
|
|
const { asset, icon } = stateFromStores2;
|
|
guildName = stateFromStores2.guildName;
|
|
const guildsBarBadges = useGuildsBarBadges(guildId, mentionCount, isMentionLowImportance);
|
|
const { badgeTopRight, badgeBottomRight, cutouts } = guildsBarBadges;
|
|
mediaState = guildsBarBadges.mediaState;
|
|
const memo = useMemo(() => ({
|
|
onPress: () => {
|
|
if (GuildStore.getGuild(guildId) != null && !isUnavailable) {
|
|
const index = SortedGuildStore.getGuildFolders().findIndex((item) => item.guildIds.includes(guildId));
|
|
if (index > -1) {
|
|
AnalyticsUtils.track(AnalyticEvents.GUILD_CLICKED, {
|
|
guild_id: guildId,
|
|
index
|
|
});
|
|
if (drawerOpen) {
|
|
AnalyticsUtils.track(AnalyticEvents.HOME_DRAWER_GUILD_CLICKED, {
|
|
guild_id: guildId,
|
|
index,
|
|
active_hook: ref.current
|
|
});
|
|
}
|
|
}
|
|
if (isLurking) {
|
|
trackGuildIconClicked(guildId);
|
|
}
|
|
transitionGuildsBarToGuildOrOpenSelectedChannel(guildId);
|
|
return void 0;
|
|
}
|
|
return AlertActionCreators.show({
|
|
title: intl.string(t.R0RpRX),
|
|
body: intl.string(t.m9gRVN)
|
|
});
|
|
},
|
|
onLongPress: isLurking ? (a0) => {
|
|
const guild = GuildStore.getGuild(guildId);
|
|
if (guild != null && !getIsScreenReaderEnabled()) {
|
|
const guildsBarGuildMenuItems = getGuildsBarGuildMenuItems(guildId, SortedGuildStore.getGuildsTree().version);
|
|
let c30815_0 = guildsBarGuildMenuItems;
|
|
if (guildsBarGuildMenuItems.length !== 0) {
|
|
const pageY = a0.nativeEvent.pageY;
|
|
state.activeIndex.set(-1);
|
|
showContextMenu({
|
|
key: guildId,
|
|
title: guild.name,
|
|
items: guildsBarGuildMenuItems,
|
|
x: 12 + token + 12,
|
|
y: pageY - token / 2,
|
|
positionX: "left",
|
|
positionY: "below",
|
|
width: token,
|
|
height: token,
|
|
state,
|
|
dividerIndexes: [],
|
|
keyboardShouldPersistTaps: "never",
|
|
requestClose: (a0) => {
|
|
if (!a0) {
|
|
const r10 = c30815_0[state.activeIndex.get()];
|
|
if (r10 != null) {
|
|
r10.action();
|
|
}
|
|
}
|
|
state.activeIndex.set(-1);
|
|
hideContextMenu();
|
|
},
|
|
onClose: () => {}
|
|
});
|
|
}
|
|
}
|
|
} : void 0
|
|
}), [guildId, token, isLurking, isUnavailable, drawerOpen]);
|
|
const memo2 = useMemo(() => {
|
|
const r23 = mentionCount != null && mentionCount > 0 ? intl.formatToPlainString(t["/uzRss"], {
|
|
guildName,
|
|
mentions: mentionCount
|
|
}) : unread === true ? intl.formatToPlainString(t.lzqe42, {
|
|
guildName
|
|
}) : intl.formatToPlainString(t["/uzRss"], {
|
|
guildName,
|
|
mentions: mentionCount
|
|
});
|
|
const r55 = [];
|
|
if (mediaState.activeEvent) {
|
|
r55.push(intl.string(t.dHvJ2p));
|
|
}
|
|
if (mediaState.liveStage) {
|
|
r55.push(intl.string(t.OO7ndG));
|
|
}
|
|
if (mediaState.screenshare) {
|
|
r55.push(intl.string(t.wsHMZ7));
|
|
}
|
|
if (mediaState.video) {
|
|
r55.push(intl.string(t.BrLCS0));
|
|
}
|
|
if (mediaState.audio) {
|
|
r55.push(intl.string(t.jPBhKy));
|
|
}
|
|
if (mediaState.activity) {
|
|
r55.push(intl.string(t.Y3Gii5));
|
|
}
|
|
return r55.length > 0 ? `${r23}, ${r55.join(" ")}` : r23;
|
|
}, [guildName, mentionCount, unread, mediaState]);
|
|
const preloadedGuildAsset = usePreloadedGuildAsset(guildId, icon, asset);
|
|
const itemDragState = useItemDragState(guildId, isDragPreview);
|
|
isDragTarget = itemDragState.isDragTarget;
|
|
const { dragState, overState, itemSize } = itemDragState;
|
|
dragDropInProgress = itemDragState.dragDropInProgress;
|
|
stateFromStores = useStateFromStores([SortedGuildStore], () => SortedGuildStore.getGuildsTree().version);
|
|
const memo3 = useMemo(() => {
|
|
let c27878_0;
|
|
const guildsBarGuildMenuItems = getGuildsBarGuildMenuItems(guildId, stateFromStores);
|
|
const guildsBarGuildAccessibilityActions = getGuildsBarGuildAccessibilityActions(guildId, stateFromStores);
|
|
const r20 = [...guildsBarGuildMenuItems.map((guildsBarGuildMenuItem) => ({
|
|
name: guildsBarGuildMenuItem.label,
|
|
label: guildsBarGuildMenuItem.label,
|
|
action: guildsBarGuildMenuItem.action
|
|
})), ...guildsBarGuildAccessibilityActions.map((guildsBarGuildAccessibilityAction) => ({
|
|
name: guildsBarGuildAccessibilityAction.name,
|
|
label: guildsBarGuildAccessibilityAction.label,
|
|
action: guildsBarGuildAccessibilityAction.action
|
|
}))];
|
|
c27878_0 = r20;
|
|
return {
|
|
accessibilityActions: r20.map((item) => ({
|
|
name: item.name,
|
|
label: item.label
|
|
})),
|
|
onAccessibilityAction: (c30816_0) => {
|
|
const r7 = c27878_0.find((item) => item.name === c30816_0.nativeEvent.actionName);
|
|
if (r7 != null) {
|
|
const action = r7.action;
|
|
if (action != null) {
|
|
action.call(r7);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}, [guildId, stateFromStores]);
|
|
const { accessibilityActions, onAccessibilityAction: onAccessibilityAction2 } = memo3;
|
|
sharedValue = useSharedValue(guildId);
|
|
const R = function R(a0) {
|
|
const r9 = dragDropInProgress.get() && sharedValue.get() === guildId && !isDragTarget;
|
|
let r15 = guildId;
|
|
if (guildId == null) {
|
|
r15 = null;
|
|
}
|
|
sharedValue.set(r15);
|
|
return {
|
|
animations: {
|
|
originY: r9 ? _spring.withSpring(a0.targetOriginY, TRANSITION_PHYSICS, "animate-always") : a0.targetOriginY,
|
|
height: r9 ? _spring.withSpring(a0.targetHeight, TRANSITION_PHYSICS, "animate-always") : a0.targetHeight
|
|
},
|
|
initialValues: {
|
|
originY: a0.currentOriginY,
|
|
height: a0.currentHeight
|
|
}
|
|
};
|
|
};
|
|
R.__closure = {
|
|
dragDropInProgress,
|
|
sharedId: sharedValue,
|
|
guildId,
|
|
isDragTarget,
|
|
withSpring: _spring.withSpring,
|
|
TRANSITION_PHYSICS
|
|
};
|
|
R.__workletHash = 14096669603718;
|
|
R.__initData = __initData;
|
|
const callback2 = useCallback(R, [guildId, sharedValue, isDragTarget, dragDropInProgress]);
|
|
const cutouts2 = isDragTarget ? void 0 : cutouts;
|
|
const circle = r31 ? !r31 : selected ? !selected : !enableHome;
|
|
if (!isDragPreview) {
|
|
isDragPreview = isDragTarget;
|
|
}
|
|
return <GuildsBarAnimatedItemWrapper id={guildId} draggedItemSize={itemSize} accessibilityActions={accessibilityActions} onAccessibilityAction={onAccessibilityAction2} cutouts={cutouts2} selected={selected} isDragTarget={isDragTarget} dragState={dragState} sharedId={sharedValue} circle={circle} overState={overState} unread={unread} label={memo2} config={memo} styles={styles2} isDragPreview={isDragPreview} layout={callback2} externalChildren={<>
|
|
{badgeTopRight}
|
|
{badgeBottomRight}
|
|
</>} expandedChildren={hideExpandedChildren ? void 0 : <HomeDrawerGuildRow guildId={guildId} onActiveHookChange={callback} />}>
|
|
{isUnavailable ? <FastImage source={Module14998} style={styles.guildIcon} /> : preloadedGuildAsset != null ? <FastImage source={preloadedGuildAsset} style={styles.guildIcon} /> : <GuildIcon value={guildName} selected={selected} animate={selected} size={GuildIconSizes.LARGE} />}
|
|
</GuildsBarAnimatedItemWrapper>;
|
|
});
|
|
export default r79;
|