Pinned Message: Fix disappearing on chat change (#5270)
This commit is contained in:
parent
00780ece5e
commit
c6d30e8cb8
@ -45,7 +45,7 @@ export default function usePinnedMessage(
|
||||
if (currentPinnedIndex >= pinnedLength) {
|
||||
setPinnedIndexByKey({
|
||||
...getPinnedIndexByKey(),
|
||||
[key]: Math.max(0, pinnedLength - 1),
|
||||
[key]: clampIndex(pinnedLength - 1),
|
||||
});
|
||||
}
|
||||
}, [getPinnedIndexByKey, key, pinnedIds?.length, setPinnedIndexByKey]);
|
||||
@ -68,7 +68,7 @@ export default function usePinnedMessage(
|
||||
const newPinnedIndex = pinnedIds.indexOf(loadingPinnedId);
|
||||
setPinnedIndexByKey({
|
||||
...getPinnedIndexByKey(),
|
||||
[key]: newPinnedIndex,
|
||||
[key]: clampIndex(newPinnedIndex),
|
||||
});
|
||||
setLoadingPinnedId(undefined);
|
||||
}
|
||||
@ -87,11 +87,10 @@ export default function usePinnedMessage(
|
||||
|
||||
if (focusedMessageId) {
|
||||
const pinnedIndexAboveFocused = pinnedIds.findIndex((id) => id < focusedMessageId);
|
||||
const newIndex = pinnedIndexAboveFocused !== -1 ? pinnedIndexAboveFocused : 0;
|
||||
|
||||
setPinnedIndexByKey({
|
||||
...getPinnedIndexByKey(),
|
||||
[key]: newIndex,
|
||||
[key]: clampIndex(pinnedIndexAboveFocused),
|
||||
});
|
||||
} else if (viewportPinnedIds.length) {
|
||||
const maxViewportPinnedId = Math.max(...viewportPinnedIds);
|
||||
@ -99,7 +98,7 @@ export default function usePinnedMessage(
|
||||
|
||||
setPinnedIndexByKey({
|
||||
...getPinnedIndexByKey(),
|
||||
[key]: newIndex,
|
||||
[key]: clampIndex(newIndex),
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -137,3 +136,7 @@ export default function usePinnedMessage(
|
||||
getLoadingPinnedId,
|
||||
};
|
||||
}
|
||||
|
||||
function clampIndex(id: number) {
|
||||
return Math.max(0, id);
|
||||
}
|
||||
|
||||
@ -49,6 +49,8 @@
|
||||
.fullWidth {
|
||||
@include mixins.header-pane;
|
||||
|
||||
height: 3.5rem;
|
||||
|
||||
.pinnedMessage {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user