feat: add error handling for state fetching in App component
This commit is contained in:
@@ -3,6 +3,8 @@ import io
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from minio import Minio
|
from minio import Minio
|
||||||
|
import redis
|
||||||
|
import os
|
||||||
|
|
||||||
DEFAULT_STATE = {
|
DEFAULT_STATE = {
|
||||||
"text": {
|
"text": {
|
||||||
@@ -27,7 +29,7 @@ MINIO_CLIENT = Minio(
|
|||||||
secure=True,
|
secure=True,
|
||||||
)
|
)
|
||||||
BUCKET = "tv-control"
|
BUCKET = "tv-control"
|
||||||
|
r = redis.Redis(host='194.15.36.205',username="default", port=12004, db=12, password=os.getenv("REDIS"))
|
||||||
def _read_state():
|
def _read_state():
|
||||||
try:
|
try:
|
||||||
with open("/app/state.json", "r") as f:
|
with open("/app/state.json", "r") as f:
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ function App() {
|
|||||||
const [imagePopup, setImagePopup] = useState<ImagePopupState>({ showing: false, image_url: "", caption: "" });
|
const [imagePopup, setImagePopup] = useState<ImagePopupState>({ showing: false, image_url: "", caption: "" });
|
||||||
const [dataCards, setDataCards] = useState<DataCard[]>([]);
|
const [dataCards, setDataCards] = useState<DataCard[]>([]);
|
||||||
const [settings, setSettings] = useState<SettingsState>({ background_url: "" });
|
const [settings, setSettings] = useState<SettingsState>({ background_url: "" });
|
||||||
|
const [fetchError, setFetchError] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleFullscreenChange = () => {
|
const handleFullscreenChange = () => {
|
||||||
@@ -86,9 +87,11 @@ function App() {
|
|||||||
setImagePopup(state.image_popup ?? { showing: false, image_url: "", caption: "" });
|
setImagePopup(state.image_popup ?? { showing: false, image_url: "", caption: "" });
|
||||||
setDataCards(state.data_cards ?? []);
|
setDataCards(state.data_cards ?? []);
|
||||||
setSettings(state.settings ?? { background_url: "" });
|
setSettings(state.settings ?? { background_url: "" });
|
||||||
|
setFetchError(false);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error pulling state:", error);
|
console.error("Error pulling state:", error);
|
||||||
|
setFetchError(true);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -113,6 +116,13 @@ function App() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-screen h-screen relative">
|
<div className="w-screen h-screen relative">
|
||||||
|
{fetchError && (
|
||||||
|
<div className="absolute inset-0 z-50 flex flex-col items-center justify-center bg-black/80 backdrop-blur-sm">
|
||||||
|
<span className="text-red-500 text-[10rem] leading-none select-none">!</span>
|
||||||
|
<p className="text-white text-5xl font-bold mt-4">Connection failed</p>
|
||||||
|
<p className="text-gray-400 text-2xl mt-3">Retrying every 5 seconds…</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{settings.background_url && (
|
{settings.background_url && (
|
||||||
<img
|
<img
|
||||||
src={settings.background_url}
|
src={settings.background_url}
|
||||||
|
|||||||
Reference in New Issue
Block a user