Updated height calculation
This commit is contained in:
parent
ed53c17597
commit
0cd703da54
3 changed files with 7 additions and 28 deletions
|
|
@ -10,11 +10,6 @@ import { useSocket } from "@tensamin/ttp/context";
|
||||||
import { useCrypto } from "@tensamin/crypto/context";
|
import { useCrypto } from "@tensamin/crypto/context";
|
||||||
import { log, toast } from "@tensamin/shared/log";
|
import { log, toast } from "@tensamin/shared/log";
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes InputComponent.
|
|
||||||
* @param none This function has no parameters.
|
|
||||||
* @returns unknown.
|
|
||||||
*/
|
|
||||||
export default function InputComponent() {
|
export default function InputComponent() {
|
||||||
const [value, setValue] = React.useState("");
|
const [value, setValue] = React.useState("");
|
||||||
const [invertEnterBehavior, setInvertEnterBehavior] = React.useState(false);
|
const [invertEnterBehavior, setInvertEnterBehavior] = React.useState(false);
|
||||||
|
|
@ -49,12 +44,14 @@ export default function InputComponent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentSharedSecret) {
|
if (!currentSharedSecret) {
|
||||||
toast("error", "Conversation key not ready yet");
|
toast("error", "Still getting shared secret...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const height = currentValue.split("\n").length * 24 + 16; // 24px per line + 16px padding
|
||||||
|
|
||||||
const reference = addLiveMessage({
|
const reference = addLiveMessage({
|
||||||
height: 0,
|
height,
|
||||||
not_encrypted: true,
|
not_encrypted: true,
|
||||||
timestamp: time,
|
timestamp: time,
|
||||||
content: currentValue,
|
content: currentValue,
|
||||||
|
|
@ -64,7 +61,7 @@ export default function InputComponent() {
|
||||||
const encryptedContext = await encrypt(currentSharedSecret, currentValue);
|
const encryptedContext = await encrypt(currentSharedSecret, currentValue);
|
||||||
|
|
||||||
send("message_send", {
|
send("message_send", {
|
||||||
height: 0,
|
height,
|
||||||
content: encryptedContext,
|
content: encryptedContext,
|
||||||
receiver_id: currentUserId,
|
receiver_id: currentUserId,
|
||||||
send_time: time,
|
send_time: time,
|
||||||
|
|
|
||||||
|
|
@ -62,26 +62,7 @@ export default function Screen() {
|
||||||
const virtualizer = useVirtualizer({
|
const virtualizer = useVirtualizer({
|
||||||
count: messages.length,
|
count: messages.length,
|
||||||
getScrollElement: () => scrollRef.current,
|
getScrollElement: () => scrollRef.current,
|
||||||
estimateSize: (index) => {
|
estimateSize: (index) => messages[index].height,
|
||||||
const message = messages[index];
|
|
||||||
|
|
||||||
if (!message) {
|
|
||||||
return 56;
|
|
||||||
}
|
|
||||||
|
|
||||||
let decodedContent = message.content;
|
|
||||||
try {
|
|
||||||
decodedContent = atob(message.content);
|
|
||||||
} catch {
|
|
||||||
/* noop */
|
|
||||||
}
|
|
||||||
|
|
||||||
const lineCount = decodedContent.split("\n").length;
|
|
||||||
const wrappedLineCount = Math.ceil(decodedContent.length / 42);
|
|
||||||
const fileCount = message.files?.length ?? 0;
|
|
||||||
|
|
||||||
return 28 + Math.max(lineCount, wrappedLineCount) * 20 + fileCount * 20;
|
|
||||||
},
|
|
||||||
overscan: 6,
|
overscan: 6,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
1
todo.md
1
todo.md
|
|
@ -2,3 +2,4 @@
|
||||||
- Split ttp codec into separate file
|
- Split ttp codec into separate file
|
||||||
- Add "Rename Conversations to Friends" option in settings
|
- Add "Rename Conversations to Friends" option in settings
|
||||||
- Handle live messages in notification context
|
- Handle live messages in notification context
|
||||||
|
- Add files to message height calculation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue