fix height

This commit is contained in:
PhilReact 2024-09-21 15:07:37 +03:00
parent bcf22ca5e0
commit 5a8f21bfb9
6 changed files with 33 additions and 13 deletions

View File

@ -129,7 +129,7 @@ const defaultValues: MyContextInterface = {
message: "", message: "",
}, },
}; };
export let isMobile = true export let isMobile = false
const isMobileDevice = () => { const isMobileDevice = () => {
const userAgent = navigator.userAgent || navigator.vendor || window.opera; const userAgent = navigator.userAgent || navigator.vendor || window.opera;
@ -313,6 +313,7 @@ function App() {
const [apiKey, setApiKey] = useState(""); const [apiKey, setApiKey] = useState("");
const [isOpenSendQort, setIsOpenSendQort] = useState(false) const [isOpenSendQort, setIsOpenSendQort] = useState(false)
const [isOpenSendQortSuccess, setIsOpenSendQortSuccess] = useState(false) const [isOpenSendQortSuccess, setIsOpenSendQortSuccess] = useState(false)
const [rootHeight, setRootHeight] = useState('100%')
useEffect(() => { useEffect(() => {
if(!isMobile) return if(!isMobile) return
// Function to set the height of the app to the viewport height // Function to set the height of the app to the viewport height
@ -320,6 +321,7 @@ function App() {
const height = window.visualViewport ? window.visualViewport.height : window.innerHeight; const height = window.visualViewport ? window.visualViewport.height : window.innerHeight;
// Set the height to the root element (usually #root) // Set the height to the root element (usually #root)
document.getElementById('root').style.height = height + "px"; document.getElementById('root').style.height = height + "px";
setRootHeight(height + "px")
}; };
// Set the initial height // Set the initial height
@ -1619,6 +1621,7 @@ function App() {
onOk, onOk,
show, show,
message, message,
rootHeight
}} }}
> >
<Box <Box

View File

@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react'
import { objectToBase64 } from '../../qdn/encryption/group-encryption' import { objectToBase64 } from '../../qdn/encryption/group-encryption'
import { ChatList } from './ChatList' import { ChatList } from './ChatList'
@ -46,6 +46,11 @@ export const ChatDirect = ({ myAddress, isNewChat, selectedDirect, setSelectedDi
const setEditorRef = (editorInstance) => { const setEditorRef = (editorInstance) => {
editorRef.current = editorInstance; editorRef.current = editorInstance;
}; };
const [, forceUpdate] = useReducer((x) => x + 1, 0);
const triggerRerender = () => {
forceUpdate(); // Trigger re-render by updating the state
};
const publicKeyOfRecipientRef = useRef(null) const publicKeyOfRecipientRef = useRef(null)
console.log({messages}) console.log({messages})
const getPublicKeyFunc = async (address)=> { const getPublicKeyFunc = async (address)=> {
@ -276,6 +281,9 @@ const clearEditorContent = () => {
editorRef.current?.chain().blur().run(); editorRef.current?.chain().blur().run();
setIsFocusedParent(false) setIsFocusedParent(false)
executeEvent("sent-new-message-group", {}) executeEvent("sent-new-message-group", {})
setTimeout(() => {
triggerRerender();
}, 300);
}, 200); }, 200);
} }
} }

View File

@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react'
import { CreateCommonSecret } from './CreateCommonSecret' import { CreateCommonSecret } from './CreateCommonSecret'
import { reusableGet } from '../../qdn/publish/pubish' import { reusableGet } from '../../qdn/publish/pubish'
import { uint8ArrayToObject } from '../../backgroundFunctions/encryption' import { uint8ArrayToObject } from '../../backgroundFunctions/encryption'
@ -44,7 +44,11 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
const groupSocketTimeoutRef = useRef(null); // Group Socket Timeout reference const groupSocketTimeoutRef = useRef(null); // Group Socket Timeout reference
const editorRef = useRef(null); const editorRef = useRef(null);
const { queueChats, addToQueue, processWithNewMessages } = useMessageQueue(); const { queueChats, addToQueue, processWithNewMessages } = useMessageQueue();
const [, forceUpdate] = useReducer((x) => x + 1, 0);
const triggerRerender = () => {
forceUpdate(); // Trigger re-render by updating the state
};
const setEditorRef = (editorInstance) => { const setEditorRef = (editorInstance) => {
editorRef.current = editorInstance; editorRef.current = editorInstance;
}; };
@ -292,6 +296,9 @@ const clearEditorContent = () => {
editorRef.current?.chain().blur().run(); editorRef.current?.chain().blur().run();
setIsFocusedParent(false) setIsFocusedParent(false)
executeEvent("sent-new-message-group", {}) executeEvent("sent-new-message-group", {})
setTimeout(() => {
triggerRerender();
}, 300);
}, 200); }, 200);
} }
} }

View File

@ -143,7 +143,7 @@ export const GroupAnnouncements = ({
const [selectedAnnouncement, setSelectedAnnouncement] = useState(null); const [selectedAnnouncement, setSelectedAnnouncement] = useState(null);
const [isFocusedParent, setIsFocusedParent] = useState(false); const [isFocusedParent, setIsFocusedParent] = useState(false);
const { show } = React.useContext(MyContext); const { show, rootHeight } = React.useContext(MyContext);
const [openSnack, setOpenSnack] = React.useState(false); const [openSnack, setOpenSnack] = React.useState(false);
const [infoSnack, setInfoSnack] = React.useState(null); const [infoSnack, setInfoSnack] = React.useState(null);
const hasInitialized = useRef(false); const hasInitialized = useRef(false);
@ -488,7 +488,7 @@ export const GroupAnnouncements = ({
<div <div
style={{ style={{
// reference to change height // reference to change height
height: isMobile ? `calc(${getRootHeight()} - 127px` : "100vh", height: isMobile ? `calc(${rootHeight} - 127px` : "100vh",
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
width: "100%", width: "100%",
@ -514,7 +514,7 @@ export const GroupAnnouncements = ({
<div <div
style={{ style={{
// reference to change height // reference to change height
height: isMobile ? `calc(${getRootHeight()} - 127px` : "100vh", height: isMobile ? `calc(${rootHeight} - 127px` : "100vh",
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
width: "100%", width: "100%",

View File

@ -1,12 +1,13 @@
import React, { import React, {
useCallback, useCallback,
useContext,
useEffect, useEffect,
useMemo, useMemo,
useRef, useRef,
useState, useState,
} from "react"; } from "react";
import { GroupMail } from "../Group/Forum/GroupMail"; import { GroupMail } from "../Group/Forum/GroupMail";
import { isMobile } from "../../App"; import { MyContext, isMobile } from "../../App";
import { getRootHeight } from "../../utils/mobile/mobileUtils"; import { getRootHeight } from "../../utils/mobile/mobileUtils";
@ -25,6 +26,7 @@ export const GroupForum = ({
defaultThread, defaultThread,
setDefaultThread setDefaultThread
}) => { }) => {
const { rootHeight } = useContext(MyContext);
const [isMoved, setIsMoved] = useState(false); const [isMoved, setIsMoved] = useState(false);
useEffect(() => { useEffect(() => {
if (hide) { if (hide) {
@ -38,7 +40,7 @@ export const GroupForum = ({
<div <div
style={{ style={{
// reference to change height // reference to change height
height: isMobile ? `calc(${getRootHeight()} - 127px` : "100vh", height: isMobile ? `calc(${rootHeight} - 127px` : "100vh",
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
width: "100%", width: "100%",

View File

@ -398,7 +398,7 @@ export const Group = ({
const [openAddGroup, setOpenAddGroup] = useState(false); const [openAddGroup, setOpenAddGroup] = useState(false);
const [isInitialGroups, setIsInitialGroups] = useState(false); const [isInitialGroups, setIsInitialGroups] = useState(false);
const [openManageMembers, setOpenManageMembers] = useState(false); const [openManageMembers, setOpenManageMembers] = useState(false);
const { setMemberGroups, memberGroups } = useContext(MyContext); const { setMemberGroups, memberGroups, rootHeight } = useContext(MyContext);
const lastGroupNotification = useRef<null | number>(null); const lastGroupNotification = useRef<null | number>(null);
const [timestampEnterData, setTimestampEnterData] = useState({}); const [timestampEnterData, setTimestampEnterData] = useState({});
const [chatMode, setChatMode] = useState("groups"); const [chatMode, setChatMode] = useState("groups");
@ -1552,7 +1552,7 @@ export const Group = ({
width: isMobile ? "100%" : "380px", width: isMobile ? "100%" : "380px",
flexDirection: "column", flexDirection: "column",
alignItems: "flex-start", alignItems: "flex-start",
height: isMobile ? `calc(${getRootHeight()} - 45px)` : "100%", height: isMobile ? `calc(${rootHeight} - 45px)` : "100%",
background: !isMobile && 'var(--bg-primary)', background: !isMobile && 'var(--bg-primary)',
borderRadius: !isMobile && '0px 15px 15px 0px' borderRadius: !isMobile && '0px 15px 15px 0px'
}} }}
@ -2266,7 +2266,7 @@ export const Group = ({
top: "0px", top: "0px",
background: "#27282c", background: "#27282c",
zIndex: 5, zIndex: 5,
height: isMobile && `calc(${getRootHeight()} - 45px)`, height: isMobile && `calc(${rootHeight} - 45px)`,
}} }}
> >
<ChatDirect <ChatDirect
@ -2542,7 +2542,7 @@ export const Group = ({
top: "0px", top: "0px",
background: "#27282c", background: "#27282c",
zIndex: 5, zIndex: 5,
height: isMobile && `calc(${getRootHeight()} - 45px)`, height: isMobile && `calc(${rootHeight} - 45px)`,
}} }}
> >
<Box <Box