mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-24 06:32:08 -05:00
Highlight messages we jump to.
This commit is contained in:
parent
362e7452fe
commit
7a5ace2def
5 changed files with 31 additions and 5 deletions
|
@ -28,12 +28,14 @@ interface Props {
|
||||||
attachContext?: boolean;
|
attachContext?: boolean;
|
||||||
queued?: QueuedMessage;
|
queued?: QueuedMessage;
|
||||||
message: MessageObject;
|
message: MessageObject;
|
||||||
|
highlight?: boolean;
|
||||||
contrast?: boolean;
|
contrast?: boolean;
|
||||||
content?: Children;
|
content?: Children;
|
||||||
head?: boolean;
|
head?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Message({
|
function Message({
|
||||||
|
highlight,
|
||||||
attachContext,
|
attachContext,
|
||||||
message,
|
message,
|
||||||
contrast,
|
contrast,
|
||||||
|
@ -72,6 +74,7 @@ function Message({
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<MessageBase
|
<MessageBase
|
||||||
|
highlight={highlight}
|
||||||
head={head && !(message.replies && message.replies.length > 0)}
|
head={head && !(message.replies && message.replies.length > 0)}
|
||||||
contrast={contrast}
|
contrast={contrast}
|
||||||
sending={typeof queued !== "undefined"}
|
sending={typeof queued !== "undefined"}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import styled, { css } from "styled-components";
|
import styled, { css, keyframes } from "styled-components";
|
||||||
import { decodeTime } from "ulid";
|
import { decodeTime } from "ulid";
|
||||||
|
|
||||||
import { Text } from "preact-i18n";
|
import { Text } from "preact-i18n";
|
||||||
|
@ -17,8 +17,15 @@ export interface BaseMessageProps {
|
||||||
blocked?: boolean;
|
blocked?: boolean;
|
||||||
sending?: boolean;
|
sending?: boolean;
|
||||||
contrast?: boolean;
|
contrast?: boolean;
|
||||||
|
highlight?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const highlight = keyframes`
|
||||||
|
0% { background: var(--mention); }
|
||||||
|
66% { background: var(--mention); }
|
||||||
|
100% { background: transparent; }
|
||||||
|
`;
|
||||||
|
|
||||||
export default styled.div<BaseMessageProps>`
|
export default styled.div<BaseMessageProps>`
|
||||||
display: flex;
|
display: flex;
|
||||||
overflow: none;
|
overflow: none;
|
||||||
|
@ -70,6 +77,14 @@ export default styled.div<BaseMessageProps>`
|
||||||
color: var(--error);
|
color: var(--error);
|
||||||
`}
|
`}
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.highlight &&
|
||||||
|
css`
|
||||||
|
animation-name: ${highlight};
|
||||||
|
animation-timing-function: ease;
|
||||||
|
animation-duration: 3s;
|
||||||
|
`}
|
||||||
|
|
||||||
.detail {
|
.detail {
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
@ -35,9 +35,10 @@ type SystemMessageParsed =
|
||||||
interface Props {
|
interface Props {
|
||||||
attachContext?: boolean;
|
attachContext?: boolean;
|
||||||
message: MessageObject;
|
message: MessageObject;
|
||||||
|
highlight?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SystemMessage({ attachContext, message }: Props) {
|
export function SystemMessage({ attachContext, message, highlight }: Props) {
|
||||||
const ctx = useForceUpdate();
|
const ctx = useForceUpdate();
|
||||||
|
|
||||||
let data: SystemMessageParsed;
|
let data: SystemMessageParsed;
|
||||||
|
@ -143,6 +144,7 @@ export function SystemMessage({ attachContext, message }: Props) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MessageBase
|
<MessageBase
|
||||||
|
highlight={highlight}
|
||||||
onContextMenu={
|
onContextMenu={
|
||||||
attachContext
|
attachContext
|
||||||
? attachContextMenu("Menu", {
|
? attachContextMenu("Menu", {
|
||||||
|
|
|
@ -60,7 +60,9 @@ export function MessageArea({ id }: Props) {
|
||||||
const status = useContext(StatusContext);
|
const status = useContext(StatusContext);
|
||||||
const { focusTaken } = useContext(IntermediateContext);
|
const { focusTaken } = useContext(IntermediateContext);
|
||||||
|
|
||||||
|
// ? Required data for message links.
|
||||||
const { message } = useParams<{ message: string }>();
|
const { message } = useParams<{ message: string }>();
|
||||||
|
const [highlight, setHighlight] = useState<string | undefined>(undefined);
|
||||||
|
|
||||||
// ? This is the scroll container.
|
// ? This is the scroll container.
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
@ -99,7 +101,7 @@ export function MessageArea({ id }: Props) {
|
||||||
});
|
});
|
||||||
} else if (scrollState.current.type === "ScrollToView") {
|
} else if (scrollState.current.type === "ScrollToView") {
|
||||||
document.getElementById(scrollState.current.id)
|
document.getElementById(scrollState.current.id)
|
||||||
?.scrollIntoView();
|
?.scrollIntoView({ block: 'center' });
|
||||||
|
|
||||||
setScrollState({ type: "Free" });
|
setScrollState({ type: "Free" });
|
||||||
} else if (scrollState.current.type === "OffsetTop") {
|
} else if (scrollState.current.type === "OffsetTop") {
|
||||||
|
@ -170,6 +172,7 @@ export function MessageArea({ id }: Props) {
|
||||||
// ? If message present or changes, load it as well.
|
// ? If message present or changes, load it as well.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (message) {
|
if (message) {
|
||||||
|
setHighlight(message);
|
||||||
SingletonMessageRenderer.init(id, message);
|
SingletonMessageRenderer.init(id, message);
|
||||||
|
|
||||||
let channel = client.channels.get(id);
|
let channel = client.channels.get(id);
|
||||||
|
@ -284,7 +287,7 @@ export function MessageArea({ id }: Props) {
|
||||||
</RequiresOnline>
|
</RequiresOnline>
|
||||||
)}
|
)}
|
||||||
{state.type === "RENDER" && (
|
{state.type === "RENDER" && (
|
||||||
<MessageRenderer id={id} state={state} />
|
<MessageRenderer id={id} state={state} highlight={highlight} />
|
||||||
)}
|
)}
|
||||||
{state.type === "EMPTY" && <ConversationStart id={id} />}
|
{state.type === "EMPTY" && <ConversationStart id={id} />}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,6 +28,7 @@ import MessageEditor from "./MessageEditor";
|
||||||
interface Props {
|
interface Props {
|
||||||
id: string;
|
id: string;
|
||||||
state: RenderState;
|
state: RenderState;
|
||||||
|
highlight?: string;
|
||||||
queue: QueuedMessage[];
|
queue: QueuedMessage[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ const BlockedMessage = styled.div`
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function MessageRenderer({ id, state, queue }: Props) {
|
function MessageRenderer({ id, state, queue, highlight }: Props) {
|
||||||
if (state.type !== "RENDER") return null;
|
if (state.type !== "RENDER") return null;
|
||||||
|
|
||||||
const client = useContext(AppContext);
|
const client = useContext(AppContext);
|
||||||
|
@ -132,6 +133,7 @@ function MessageRenderer({ id, state, queue }: Props) {
|
||||||
key={message._id}
|
key={message._id}
|
||||||
message={message}
|
message={message}
|
||||||
attachContext
|
attachContext
|
||||||
|
highlight={highlight === message._id}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,6 +160,7 @@ function MessageRenderer({ id, state, queue }: Props) {
|
||||||
) : undefined
|
) : undefined
|
||||||
}
|
}
|
||||||
attachContext
|
attachContext
|
||||||
|
highlight={highlight === message._id}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue