import { useLaunch } from '@tarojs/taro';

import { PropsWithChildren } from 'react';
import { Provider } from 'react-redux';

import { REFRESH_UNREAD_COUNT_TIME } from '@/constants/message';
import http from '@/http';
import store from '@/store';
import { requestUnreadMessageCount } from '@/utils/message';
import qiniuUpload from '@/utils/qiniu-upload';
import { requestUserInfo, updateLastLoginTime } from '@/utils/user';

import './app.less';

function App({ children }: PropsWithChildren<BL.Anything>) {
  useLaunch(async () => {
    console.log('App launched.');
    await http.init();
    requestUserInfo();
    updateLastLoginTime();
    qiniuUpload.init();
    requestUnreadMessageCount();
    setInterval(() => requestUnreadMessageCount(), REFRESH_UNREAD_COUNT_TIME);
  });

  return <Provider store={store}>{children}</Provider>;
}

export default App;
