fix
This commit is contained in:
5
.idea/material_theme_project_new.xml
generated
5
.idea/material_theme_project_new.xml
generated
@@ -3,7 +3,10 @@
|
|||||||
<component name="MaterialThemeProjectNewConfig">
|
<component name="MaterialThemeProjectNewConfig">
|
||||||
<option name="metadata">
|
<option name="metadata">
|
||||||
<MTProjectMetadataState>
|
<MTProjectMetadataState>
|
||||||
<option name="userId" value="3d6f1b06:19d820f26b8:-7ffd" />
|
<option name="migrated" value="true" />
|
||||||
|
<option name="pristineConfig" value="false" />
|
||||||
|
<option name="userId" value="2c1a2bb7:18a988f44a2:-8000" />
|
||||||
|
<option name="version" value="8.13.2" />
|
||||||
</MTProjectMetadataState>
|
</MTProjectMetadataState>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export function WritingChecker() {
|
|||||||
const [improvedExpanded, setImprovedExpanded] = useState(false)
|
const [improvedExpanded, setImprovedExpanded] = useState(false)
|
||||||
const [remaining, setRemaining] = useState(getRemainingChecks)
|
const [remaining, setRemaining] = useState(getRemainingChecks)
|
||||||
|
|
||||||
const { mutate: checkWriting, isPending, isError, error, data: feedback } = useWritingCheck()
|
const { mutate: checkWriting, isPending, isError, error, data: feedback, reset: resetMutation } = useWritingCheck()
|
||||||
const { requireAuth } = useRequireAuth()
|
const { requireAuth } = useRequireAuth()
|
||||||
const user = useAuthStore((s) => s.user)
|
const user = useAuthStore((s) => s.user)
|
||||||
const { mutate: awardActivity } = useAwardActivity()
|
const { mutate: awardActivity } = useAwardActivity()
|
||||||
@@ -28,12 +28,13 @@ export function WritingChecker() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
setRemaining(getRemainingChecks())
|
setRemaining(getRemainingChecks())
|
||||||
|
resetMutation()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
countTodayWritingSubmissions(user.id).then((used) => {
|
countTodayWritingSubmissions(user.id).then((used) => {
|
||||||
setRemaining(AUTH_LIMIT - used)
|
setRemaining(AUTH_LIMIT - used)
|
||||||
})
|
})
|
||||||
}, [user])
|
}, [user, resetMutation])
|
||||||
|
|
||||||
const charCount = text.length
|
const charCount = text.length
|
||||||
const canSubmit = text.trim().length > 0 && remaining > 0 && charCount <= MAX_CHARS && !isPending
|
const canSubmit = text.trim().length > 0 && remaining > 0 && charCount <= MAX_CHARS && !isPending
|
||||||
|
|||||||
@@ -13,7 +13,18 @@ async function callEdgeFunction(content: string): Promise<WritingFeedback> {
|
|||||||
body: { content },
|
body: { content },
|
||||||
})
|
})
|
||||||
|
|
||||||
if (error) throw new Error(error.message ?? "Đã có lỗi khi chấm bài. Vui lòng thử lại.")
|
if (error) {
|
||||||
|
// The Supabase SDK wraps non-2xx responses in a generic FunctionsHttpError.
|
||||||
|
// Try to parse the actual error body returned by the edge function.
|
||||||
|
try {
|
||||||
|
const body = await (error as unknown as { context: Response }).context.json()
|
||||||
|
if (body?.error) throw new Error(body.error)
|
||||||
|
} catch {
|
||||||
|
// ignore parse failure, fall through to generic message
|
||||||
|
}
|
||||||
|
throw new Error("Đã có lỗi khi chấm bài. Vui lòng thử lại.")
|
||||||
|
}
|
||||||
|
|
||||||
if (!data) throw new Error("Phản hồi từ AI không hợp lệ. Vui lòng thử lại.")
|
if (!data) throw new Error("Phản hồi từ AI không hợp lệ. Vui lòng thử lại.")
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user