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 { useDispatch, useSelector } from "react-redux";
|
||||
import auth, { selectAuthenticated, selectUsername } from "@/store/auth.ts";
|
||||
import { selectAuthenticated, selectUsername } from "@/store/auth.ts";
|
||||
import {
|
||||
closeMarket,
|
||||
selectCurrent,
|
||||
@ -8,7 +8,7 @@ import {
|
||||
selectMaskItem,
|
||||
useConversationActions,
|
||||
} from "@/store/chat.ts";
|
||||
import React, { useCallback, useRef, useState } from "react";
|
||||
import React, { useRef, useState } from "react";
|
||||
import { ConversationInstance } from "@/api/types.tsx";
|
||||
import { useToast } from "@/components/ui/use-toast.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 { cn } from "@/components/ui/lib/utils.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 = {
|
||||
target: ConversationInstance | null;
|
||||
@ -332,25 +329,11 @@ function SidebarConversationList({
|
||||
|
||||
function SidebarMenu() {
|
||||
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 (
|
||||
<div className={`sidebar-menu`}>
|
||||
<Separator orientation={`horizontal`} className={`mb-2`} />
|
||||
<MenuBar className={`menu-bar`}>
|
||||
<Button variant={`ghost`} className={`sidebar-wrapper`}
|
||||
onClick={() => {
|
||||
updateQuota();
|
||||
handleRefreshSubscription();
|
||||
}}>
|
||||
<Button variant={`ghost`} className={`sidebar-wrapper`}>
|
||||
<Avatar username={username} />
|
||||
<span className={`username`}>{username}</span>
|
||||
<MoreHorizontal className={`h-4 w-4`} />
|
||||
|
@ -98,7 +98,10 @@ function QuotaDialog() {
|
||||
const dispatch = useDispatch();
|
||||
useEffectAsync(async () => {
|
||||
if (!auth) return;
|
||||
await refreshQuota();
|
||||
const task = setInterval(() => refreshQuota(dispatch), 5000);
|
||||
await refreshQuota(dispatch);
|
||||
|
||||
return () => clearInterval(task);
|
||||
}, [auth]);
|
||||
|
||||
return (
|
||||
@ -319,7 +322,7 @@ function QuotaDialog() {
|
||||
}),
|
||||
});
|
||||
setRedeem("");
|
||||
await refreshQuota();
|
||||
await refreshQuota(dispatch);
|
||||
} else {
|
||||
toast({
|
||||
title: t("buy.exchange-failed"),
|
||||
|
@ -115,7 +115,10 @@ function SubscriptionDialog() {
|
||||
const dispatch = useDispatch();
|
||||
useEffectAsync(async () => {
|
||||
if (!auth) return;
|
||||
const task = setInterval(() => refreshSubscription(dispatch), 10000);
|
||||
await refreshSubscription(dispatch);
|
||||
|
||||
return () => clearInterval(task);
|
||||
}, [auth]);
|
||||
|
||||
return (
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
||||
import { RootState } from "./index.ts";
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { AppDispatch, RootState } from "./index.ts";
|
||||
import { getQuota } from "@/api/quota.ts";
|
||||
|
||||
export const quotaSlice = createSlice({
|
||||
@ -49,10 +49,7 @@ export const quotaValueSelector = (state: RootState): number =>
|
||||
state.quota.quota;
|
||||
export const quotaSelector = (state: RootState): number => state.quota.quota;
|
||||
|
||||
export const refreshQuota = createAsyncThunk(
|
||||
'quota/refreshQuota',
|
||||
async (_, { dispatch }) => {
|
||||
const quota = await getQuota();
|
||||
dispatch(setQuota(quota));
|
||||
}
|
||||
);
|
||||
export const refreshQuota = async (dispatch: AppDispatch) => {
|
||||
const quota = await getQuota();
|
||||
dispatch(setQuota(quota));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user