Commit c48b7d0f authored by 健杭 徐's avatar 健杭 徐
Browse files

finish

parent 50dc23f5
import { COMMENT_ADD } from "./assets/const";
async function AddComment({ name, onSuccess }: { name: string; onSuccess: () => void; }) {
const textInput = document.getElementById('textInput') as HTMLInputElement;
const content = textInput.value;
......@@ -11,7 +13,7 @@ async function AddComment({ name, onSuccess }: { name: string; onSuccess: () =>
}
try {
const response = await fetch('http://localhost:8080/comment/add', {
const response = await fetch(COMMENT_ADD, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, content, created_at: new Date().toISOString() })
......
import { useState, useEffect, useRef } from 'react';
import { COMMENT_GET, COMMENT_DEL } from './assets/const'
function useInterval(callback: () => void, delay: number | null) {
const savedCallback = useRef<() => void>(undefined);
......@@ -37,7 +38,7 @@ export function CommentSection({ refreshTrigger }: { refreshTrigger: number }) {
const loadComments = async (page: number) => {
try {
const response = await fetch(`http://localhost:8080/comment/get?page=${page}&size=${pageSize}`);
const response = await fetch(COMMENT_GET + `?page=${page}&size=${pageSize}`);
const result = await response.json();
if (result.code !== 0) throw new Error(result.msg);
......@@ -53,7 +54,7 @@ export function CommentSection({ refreshTrigger }: { refreshTrigger: number }) {
if (!confirm('确定要删除这条评论吗?'))
return;
try {
const response = await fetch(`http://localhost:8080/comment/delete?id=${commentId}`, {
const response = await fetch(COMMENT_DEL + `?id=${commentId}`, {
method: 'POST'
});
const result = await response.json();
......
export const COMMENT_ADD: string = 'http://localhost:8080/comment/add'
export const COMMENT_GET: string = 'http://localhost:8080/comment/get'
export const COMMENT_DEL: string = 'http://localhost:8080/comment/delete'
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment