mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-18 21:36:27 +01:00
Reset the sizes if the screen size changes
This commit is contained in:
parent
16e3457ec8
commit
981e0d65f6
@ -1,8 +1,9 @@
|
||||
import { FigureUpdateEvent, RoomUnitChatStyleComposer, UserInfoDataParser, UserInfoEvent, UserSettingsEvent } from '@nitrots/nitro-renderer';
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useBetween } from 'use-between';
|
||||
import { GetSessionDataManager, SendMessageComposer } from '../../api';
|
||||
import { GetLocalStorage, GetSessionDataManager, SendMessageComposer } from '../../api';
|
||||
import { useMessageEvent } from '../events';
|
||||
import { useLocalStorage } from '../useLocalStorage';
|
||||
|
||||
const useSessionInfoState = () =>
|
||||
{
|
||||
@ -11,6 +12,7 @@ const useSessionInfoState = () =>
|
||||
const [ chatStyleId, setChatStyleId ] = useState<number>(0);
|
||||
const [ userRespectRemaining, setUserRespectRemaining ] = useState<number>(0);
|
||||
const [ petRespectRemaining, setPetRespectRemaining ] = useState<number>(0);
|
||||
const [ screenSize, setScreenSize ] = useLocalStorage('nitro.screensize', { width: window.innerWidth, height: window.innerHeight });
|
||||
|
||||
const updateChatStyleId = (styleId: number) =>
|
||||
{
|
||||
@ -57,6 +59,34 @@ const useSessionInfoState = () =>
|
||||
setChatStyleId(parser.chatType);
|
||||
});
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
const currentScreenSize = <{ width: number, height: number }>GetLocalStorage('nitro.screensize');
|
||||
|
||||
if(currentScreenSize && ((currentScreenSize.width !== window.innerWidth) || (currentScreenSize.height !== window.innerHeight)))
|
||||
{
|
||||
let i = window.localStorage.length;
|
||||
|
||||
while(i > 0)
|
||||
{
|
||||
const key = window.localStorage.key(i);
|
||||
|
||||
if(key && key.startsWith('nitro.window')) window.localStorage.removeItem(key);
|
||||
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
const onResize = (event: UIEvent) => setScreenSize({ width: window.innerWidth, height: window.innerHeight });
|
||||
|
||||
window.addEventListener('resize', onResize);
|
||||
|
||||
return () =>
|
||||
{
|
||||
window.removeEventListener('resize', onResize);
|
||||
}
|
||||
}, [ setScreenSize ]);
|
||||
|
||||
return { userInfo, userFigure, chatStyleId, userRespectRemaining, petRespectRemaining, respectUser, respectPet, updateChatStyleId };
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user