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