2025-07-25 09:56:45 -04:00
|
|
|
import { useState, useEffect } from "react";
|
2025-06-22 09:50:36 -04:00
|
|
|
import { API_URL } from "../config";
|
2025-07-25 09:54:22 -04:00
|
|
|
|
2025-07-25 09:56:45 -04:00
|
|
|
export default function RandomMsg() {
|
|
|
|
|
const [randomMsg, setRandomMsg] = useState("");
|
2025-06-22 09:50:36 -04:00
|
|
|
|
2025-07-25 09:56:45 -04:00
|
|
|
const getRandomMsg = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_URL}/randmsg`, {
|
|
|
|
|
method: "POST",
|
2025-09-22 11:15:24 -04:00
|
|
|
headers: { "Content-Type": "application/json; charset=utf-8" },
|
2025-07-25 09:56:45 -04:00
|
|
|
});
|
2025-09-22 11:15:24 -04:00
|
|
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
2025-07-25 09:56:45 -04:00
|
|
|
const data = await response.json();
|
2025-09-22 11:15:24 -04:00
|
|
|
if (data?.msg) setRandomMsg(data.msg.replace(/<br\s*\/?>/gi, "\n"));
|
2025-07-25 09:56:45 -04:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Failed to fetch random message:", err);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-06-22 09:50:36 -04:00
|
|
|
|
2025-09-22 11:15:24 -04:00
|
|
|
useEffect(() => void getRandomMsg(), []);
|
2025-06-22 09:50:36 -04:00
|
|
|
|
2025-07-25 09:56:45 -04:00
|
|
|
return (
|
|
|
|
|
<div className="random-msg-container">
|
|
|
|
|
<div className="random-msg">
|
|
|
|
|
{randomMsg && (
|
|
|
|
|
<small>
|
|
|
|
|
<i>{randomMsg}</i>
|
|
|
|
|
</small>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-09-22 11:15:24 -04:00
|
|
|
{randomMsg && (
|
|
|
|
|
<button
|
|
|
|
|
aria-label="New footer message"
|
|
|
|
|
type="button"
|
|
|
|
|
className="flex items-center justify-center px-2 py-1 rounded-md hover:bg-neutral-200 dark:hover:bg-neutral-800 transition-opacity new-msg-button"
|
|
|
|
|
onClick={getRandomMsg}
|
|
|
|
|
>
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
width="16"
|
|
|
|
|
height="16"
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
focusable="false"
|
|
|
|
|
className="inline-block"
|
|
|
|
|
>
|
|
|
|
|
<path
|
2025-11-25 13:05:37 -05:00
|
|
|
d="M17.65 6.35a7.95 7.95 0 0 0-5.65-2.35 8 8 0 1 0 7.75 9.94h-2.08a6 6 0 1 1-5.67-7.94 5.94 5.94 0 0 1 4.22 1.78L13 11h7V4z"
|
|
|
|
|
fill="currentColor"
|
2025-09-22 11:15:24 -04:00
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-07-25 09:56:45 -04:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|