feat: reconnecting status

This commit is contained in:
Tristan Yang
2023-09-05 08:58:46 +08:00
parent 48ff349e66
commit dea5185f66
2 changed files with 10 additions and 7 deletions
+4 -3
View File
@@ -3,7 +3,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { UploadFileData } from "@/hooks/useUploadFile"; import { UploadFileData } from "@/hooks/useUploadFile";
export type ListView = "item" | "grid"; export type ListView = "item" | "grid";
export type SSEStatus = "connecting" | "connected" | "disconnected"; export type SSEStatus = "connecting" | "connected" | "disconnected" | "reconnecting";
export interface UIState { export interface UIState {
SSEStatus: SSEStatus; SSEStatus: SSEStatus;
online: boolean; online: boolean;
@@ -46,8 +46,9 @@ const uiSlice = createSlice({
name: "ui", name: "ui",
initialState, initialState,
reducers: { reducers: {
fillUI(state, action) { fillUI(state, action: PayloadAction<Partial<UIState>>) {
return { ...initialState, ...action.payload }; const { SSEStatus, ready, online, ...rest } = action.payload;
return { ...state, ...rest };
}, },
setReady(state) { setReady(state) {
state.ready = true; state.ready = true;
+6 -4
View File
@@ -1,12 +1,13 @@
import { useAppSelector } from "@/app/store"; import { useAppSelector } from "@/app/store";
import clsx from "clsx"; import clsx from "clsx";
// import { useEffect } from "react";
// import { toast } from "react-hot-toast";
import { shallowEqual } from "react-redux"; import { shallowEqual } from "react-redux";
// import React from "react";
type Props = {}; // type Props = {};
const StreamStatus = () => {
const StreamStatus = (props: Props) => {
const status = useAppSelector((store) => store.ui.SSEStatus, shallowEqual); const status = useAppSelector((store) => store.ui.SSEStatus, shallowEqual);
return ( return (
<aside className="fixed right-2 bottom-2"> <aside className="fixed right-2 bottom-2">
<div <div
@@ -14,6 +15,7 @@ const StreamStatus = (props: Props) => {
"w-1 h-1 rounded-full", "w-1 h-1 rounded-full",
status === "connected" && "bg-green-500", status === "connected" && "bg-green-500",
status === "disconnected" && "bg-red-500", status === "disconnected" && "bg-red-500",
status === "reconnecting" && "bg-blue-500",
status === "connecting" && "bg-yellow-500" status === "connecting" && "bg-yellow-500"
)} )}
></div> ></div>