mirror of
https://github.com/coaidev/coai.git
synced 2025-05-21 14:00:13 +09:00
Revert "fix: remove repetitive quota refresh interval"
This commit is contained in:
parent
f860a99d4d
commit
1b02fade6d
@ -1,6 +1,6 @@
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import auth, { selectAuthenticated, selectUsername } from "@/store/auth.ts";
|
import { selectAuthenticated, selectUsername } from "@/store/auth.ts";
|
||||||
import {
|
import {
|
||||||
closeMarket,
|
closeMarket,
|
||||||
selectCurrent,
|
selectCurrent,
|
||||||
@ -8,7 +8,7 @@ import {
|
|||||||
selectMaskItem,
|
selectMaskItem,
|
||||||
useConversationActions,
|
useConversationActions,
|
||||||
} from "@/store/chat.ts";
|
} from "@/store/chat.ts";
|
||||||
import React, { useCallback, useRef, useState } from "react";
|
import React, { useRef, useState } from "react";
|
||||||
import { ConversationInstance } from "@/api/types.tsx";
|
import { ConversationInstance } from "@/api/types.tsx";
|
||||||
import { useToast } from "@/components/ui/use-toast.ts";
|
import { useToast } from "@/components/ui/use-toast.ts";
|
||||||
import { extractMessage, filterMessage } from "@/utils/processor.ts";
|
import { extractMessage, filterMessage } from "@/utils/processor.ts";
|
||||||
@ -46,9 +46,6 @@ import { goAuth } from "@/utils/app.ts";
|
|||||||
import Avatar from "@/components/Avatar.tsx";
|
import Avatar from "@/components/Avatar.tsx";
|
||||||
import { cn } from "@/components/ui/lib/utils.ts";
|
import { cn } from "@/components/ui/lib/utils.ts";
|
||||||
import { getNumberMemory } from "@/utils/memory.ts";
|
import { getNumberMemory } from "@/utils/memory.ts";
|
||||||
import { refreshSubscription } from "@/store/subscription.ts";
|
|
||||||
import { refreshQuota } from "@/store/quota.ts";
|
|
||||||
import { AppDispatch } from "@/store";
|
|
||||||
|
|
||||||
type Operation = {
|
type Operation = {
|
||||||
target: ConversationInstance | null;
|
target: ConversationInstance | null;
|
||||||
@ -332,25 +329,11 @@ function SidebarConversationList({
|
|||||||
|
|
||||||
function SidebarMenu() {
|
function SidebarMenu() {
|
||||||
const username = useSelector(selectUsername);
|
const username = useSelector(selectUsername);
|
||||||
const dispatch: AppDispatch = useDispatch();
|
|
||||||
const updateQuota = useCallback(() => {
|
|
||||||
dispatch(refreshQuota()); // 调用 refreshQuota 更新配额
|
|
||||||
}, [dispatch]);
|
|
||||||
const handleRefreshSubscription = async () => {
|
|
||||||
if (!auth) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await refreshSubscription(dispatch);
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<div className={`sidebar-menu`}>
|
<div className={`sidebar-menu`}>
|
||||||
<Separator orientation={`horizontal`} className={`mb-2`} />
|
<Separator orientation={`horizontal`} className={`mb-2`} />
|
||||||
<MenuBar className={`menu-bar`}>
|
<MenuBar className={`menu-bar`}>
|
||||||
<Button variant={`ghost`} className={`sidebar-wrapper`}
|
<Button variant={`ghost`} className={`sidebar-wrapper`}>
|
||||||
onClick={() => {
|
|
||||||
updateQuota();
|
|
||||||
handleRefreshSubscription();
|
|
||||||
}}>
|
|
||||||
<Avatar username={username} />
|
<Avatar username={username} />
|
||||||
<span className={`username`}>{username}</span>
|
<span className={`username`}>{username}</span>
|
||||||
<MoreHorizontal className={`h-4 w-4`} />
|
<MoreHorizontal className={`h-4 w-4`} />
|
||||||
|
@ -98,7 +98,10 @@ function QuotaDialog() {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
useEffectAsync(async () => {
|
useEffectAsync(async () => {
|
||||||
if (!auth) return;
|
if (!auth) return;
|
||||||
await refreshQuota();
|
const task = setInterval(() => refreshQuota(dispatch), 5000);
|
||||||
|
await refreshQuota(dispatch);
|
||||||
|
|
||||||
|
return () => clearInterval(task);
|
||||||
}, [auth]);
|
}, [auth]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -319,7 +322,7 @@ function QuotaDialog() {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
setRedeem("");
|
setRedeem("");
|
||||||
await refreshQuota();
|
await refreshQuota(dispatch);
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
title: t("buy.exchange-failed"),
|
title: t("buy.exchange-failed"),
|
||||||
|
@ -115,7 +115,10 @@ function SubscriptionDialog() {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
useEffectAsync(async () => {
|
useEffectAsync(async () => {
|
||||||
if (!auth) return;
|
if (!auth) return;
|
||||||
|
const task = setInterval(() => refreshSubscription(dispatch), 10000);
|
||||||
await refreshSubscription(dispatch);
|
await refreshSubscription(dispatch);
|
||||||
|
|
||||||
|
return () => clearInterval(task);
|
||||||
}, [auth]);
|
}, [auth]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
import { createSlice } from "@reduxjs/toolkit";
|
||||||
import { RootState } from "./index.ts";
|
import { AppDispatch, RootState } from "./index.ts";
|
||||||
import { getQuota } from "@/api/quota.ts";
|
import { getQuota } from "@/api/quota.ts";
|
||||||
|
|
||||||
export const quotaSlice = createSlice({
|
export const quotaSlice = createSlice({
|
||||||
@ -49,10 +49,7 @@ export const quotaValueSelector = (state: RootState): number =>
|
|||||||
state.quota.quota;
|
state.quota.quota;
|
||||||
export const quotaSelector = (state: RootState): number => state.quota.quota;
|
export const quotaSelector = (state: RootState): number => state.quota.quota;
|
||||||
|
|
||||||
export const refreshQuota = createAsyncThunk(
|
export const refreshQuota = async (dispatch: AppDispatch) => {
|
||||||
'quota/refreshQuota',
|
const quota = await getQuota();
|
||||||
async (_, { dispatch }) => {
|
dispatch(setQuota(quota));
|
||||||
const quota = await getQuota();
|
};
|
||||||
dispatch(setQuota(quota));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user