Commit c6b11083 authored by Ategon's avatar Ategon Committed by Grant
Browse files

Fix hype numbers when shown from settings

parent 3152243d
Loading
Loading
Loading
Loading
Loading
+14 −18
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ import {
  useDisclosure,
} from "@heroui/react";
import type { ClientConfig } from "@sc07-canvas/lib/net";
import { useCallback, useEffect, useReducer, useState } from "react";
import { useCallback, useEffect, useState } from "react";

import { useAppContext } from "@/contexts/AppContext";
import { useDialog } from "@/contexts/DialogContext";
@@ -137,6 +137,18 @@ const EventHype = () => {
      });
  }, []);

  useEffect(() => {
    const handle = (emoji: string, count: number) => {
      setData((current) => ({ ...current, [emoji]: count }));
    };

    network.socket.on("event_hype", handle);

    return () => {
      network.socket.off("event_hype", handle);
    };
  }, []);

  if (!config?.event.hype.enable) return undefined;

  if (user) return <EventHypeInner counts={data} config={config} />;
@@ -160,24 +172,8 @@ const EventHypeInner = ({
  doLogin?: () => void;
}) => {
  const { emojis } = config.event.hype;
  const [count, dispatch] = useReducer<
    { [emoji: string]: number },
    [[emoji: string, count: number]]
  >((prev, [emoji, count]) => ({ ...prev, [emoji]: count }), counts);
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    const handle = (emoji: string, count: number) => {
      dispatch([emoji, count]);
    };

    network.socket.on("event_hype", handle);

    return () => {
      network.socket.off("event_hype", handle);
    };
  }, []);

  const doReact = useCallback((emoji: string) => {
    if (doLogin) return doLogin();

@@ -200,7 +196,7 @@ const EventHypeInner = ({
    <>
      <div className="flex flex-row gap-1 items-center justify-center">
        {emojis.map((emoji) => (
          <Badge key={emoji} color="primary" content={count[emoji] ?? "?"}>
          <Badge key={emoji} color="primary" content={counts[emoji] ?? "?"}>
            <Button
              variant="bordered"
              className="min-w-0 text-2xl p-3"