feat: error track, app scroll

This commit is contained in:
archer
2023-09-03 17:37:14 +08:00
parent 7c16d08ec0
commit e0b23a26f2
9 changed files with 101 additions and 40 deletions

View File

@@ -42,6 +42,7 @@ function App({ Component, pageProps }: AppProps) {
const [googleClientVerKey, setGoogleVerKey] = useState<string>();
useEffect(() => {
// get init data
(async () => {
const {
feConfigs: { scripts, googleClientVerKey }
@@ -49,6 +50,21 @@ function App({ Component, pageProps }: AppProps) {
setScripts(scripts || []);
setGoogleVerKey(googleClientVerKey);
})();
// add window error track
window.onerror = function (msg, url) {
window.umami?.track('windowError', {
device: {
userAgent: navigator.userAgent,
platform: navigator.platform,
appName: navigator.appName
},
msg,
url
});
};
return () => {
window.onerror = null;
};
}, []);
useEffect(() => {

View File

@@ -1,10 +1,19 @@
import { useEffect } from 'react';
import { useRouter } from 'next/router';
import { serviceSideProps } from '@/utils/i18n';
function Error() {
const router = useRouter();
useEffect(() => {
setTimeout(() => {
router.replace('/app/list');
window.umami?.track('pageError', {
userAgent: navigator.userAgent,
platform: navigator.platform,
appName: navigator.appName
});
}, 1000);
setTimeout(() => {
router.back();
}, 2000);
}, []);
@@ -16,4 +25,12 @@ function Error() {
);
}
export async function getServerSideProps(context: any) {
console.log(context);
return {
props: { ...(await serviceSideProps(context)) }
};
}
export default Error;

View File

@@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { connectToDatabase, Chat, ChatItem } from '@/service/mongo';
import { authUser } from '@/service/utils/auth';
import { ChatSourceEnum } from '@/constants/chat';
type Props = {
chatId?: string;
@@ -29,14 +30,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
]);
}
if (appId) {
const chats = await Chat.find({
appId,
userId,
source: ChatSourceEnum.online
}).select('_id');
const chatIds = chats.map((chat) => chat._id);
await Promise.all([
Chat.deleteMany({
appId,
userId
_id: { $in: chatIds }
}),
ChatItem.deleteMany({
userId,
appId
chatId: { $in: chatIds }
})
]);
}

View File

@@ -15,29 +15,31 @@ const SliderApps = ({ appId }: { appId: string }) => {
useQuery(['loadModels'], () => loadMyApps(false));
return (
<>
<Flex
alignItems={'center'}
cursor={'pointer'}
py={2}
px={3}
borderRadius={'md'}
_hover={{ bg: 'myGray.200' }}
onClick={() => router.push('/app/list')}
>
<IconButton
mr={3}
icon={<MyIcon name={'backFill'} w={'18px'} color={'myBlue.600'} />}
bg={'white'}
boxShadow={'1px 1px 9px rgba(0,0,0,0.15)'}
h={'28px'}
size={'sm'}
borderRadius={'50%'}
aria-label={''}
/>
{t('chat.Exit Chat')}
</Flex>
<Box mt={5}>
<Flex flexDirection={'column'} h={'100%'}>
<Box px={5} py={4}>
<Flex
alignItems={'center'}
cursor={'pointer'}
py={2}
px={3}
borderRadius={'md'}
_hover={{ bg: 'myGray.200' }}
onClick={() => router.push('/app/list')}
>
<IconButton
mr={3}
icon={<MyIcon name={'backFill'} w={'18px'} color={'myBlue.600'} />}
bg={'white'}
boxShadow={'1px 1px 9px rgba(0,0,0,0.15)'}
h={'28px'}
size={'sm'}
borderRadius={'50%'}
aria-label={''}
/>
{t('chat.Exit Chat')}
</Flex>
</Box>
<Box flex={'1 0 0'} h={0} px={5} overflow={'overlay'}>
{myApps.map((item) => (
<Flex
key={item._id}
@@ -72,7 +74,7 @@ const SliderApps = ({ appId }: { appId: string }) => {
</Flex>
))}
</Box>
</>
</Flex>
);
};

View File

@@ -252,7 +252,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
</Head>
{/* pc show myself apps */}
{isPc && (
<Box p={5} borderRight={theme.borders.base} w={'220px'} flexShrink={0}>
<Box borderRight={theme.borders.base} w={'220px'} flexShrink={0}>
<SliderApps appId={appId} />
</Box>
)}