From a871b520062c111ee55c2b1678d804957df7ca5e Mon Sep 17 00:00:00 2001 From: Thibaut Valentin Date: Mon, 5 Jan 2026 11:09:22 +0100 Subject: [PATCH] feat: use blason setting --- .../fr/titionfire/ffsaf/ws/CompetitionWS.java | 4 +++ .../titionfire/ffsaf/ws/data/WelcomeInfo.java | 2 ++ src/main/webapp/src/hooks/useComb.jsx | 4 +-- src/main/webapp/src/hooks/useWS.jsx | 31 ++++++++++++++----- .../src/pages/competition/editor/CMTable.jsx | 12 +++---- .../editor/CompetitionManagerRoot.jsx | 14 +++------ .../pages/competition/editor/PubAffWindow.jsx | 9 ++++-- 7 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/main/java/fr/titionfire/ffsaf/ws/CompetitionWS.java b/src/main/java/fr/titionfire/ffsaf/ws/CompetitionWS.java index c22e5ef..d5246f3 100644 --- a/src/main/java/fr/titionfire/ffsaf/ws/CompetitionWS.java +++ b/src/main/java/fr/titionfire/ffsaf/ws/CompetitionWS.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import fr.titionfire.ffsaf.data.repository.CompetitionRepository; import fr.titionfire.ffsaf.domain.service.CompetPermService; import fr.titionfire.ffsaf.net2.MessageType; +import fr.titionfire.ffsaf.rest.data.SimpleCompetData; import fr.titionfire.ffsaf.utils.SecurityCtx; import fr.titionfire.ffsaf.ws.data.WelcomeInfo; import fr.titionfire.ffsaf.ws.recv.*; @@ -118,10 +119,13 @@ public class CompetitionWS { waitingResponse.put(connection, new HashMap<>()); }) .map(cm -> { + SimpleCompetData data = SimpleCompetData.fromModel(cm); WelcomeInfo welcomeInfo = new WelcomeInfo(); welcomeInfo.setName(cm.getName()); welcomeInfo.setPerm(connection.userData().get(UserData.TypedKey.forString("prem"))); + welcomeInfo.setShow_blason(data.isShow_blason()); + welcomeInfo.setShow_flag(data.isShow_flag()); return new MessageOut(UUID.randomUUID(), "welcomeInfo", MessageType.NOTIFY, welcomeInfo); }); diff --git a/src/main/java/fr/titionfire/ffsaf/ws/data/WelcomeInfo.java b/src/main/java/fr/titionfire/ffsaf/ws/data/WelcomeInfo.java index eebe679..a1dff22 100644 --- a/src/main/java/fr/titionfire/ffsaf/ws/data/WelcomeInfo.java +++ b/src/main/java/fr/titionfire/ffsaf/ws/data/WelcomeInfo.java @@ -8,4 +8,6 @@ import lombok.Data; public class WelcomeInfo { private String name; private String perm; + private boolean show_blason; + private boolean show_flag; } diff --git a/src/main/webapp/src/hooks/useComb.jsx b/src/main/webapp/src/hooks/useComb.jsx index 4f1fb7b..aa62ac0 100644 --- a/src/main/webapp/src/hooks/useComb.jsx +++ b/src/main/webapp/src/hooks/useComb.jsx @@ -25,7 +25,7 @@ function reducer(state, action) { country: action.payload.data.country, }) if (state[comb.id] === undefined || !compareCombs(comb, state[comb.id])) { - console.debug("Updating comb", comb); + //console.debug("Updating comb", comb); return { ...state, [comb.id]: comb @@ -49,7 +49,7 @@ function reducer(state, action) { for (const o of combs) { newCombs[o.id] = o; } - console.debug("Updating combs", newCombs); + //console.debug("Updating combs", newCombs); return { ...state, diff --git a/src/main/webapp/src/hooks/useWS.jsx b/src/main/webapp/src/hooks/useWS.jsx index ef5f0c0..79fce96 100644 --- a/src/main/webapp/src/hooks/useWS.jsx +++ b/src/main/webapp/src/hooks/useWS.jsx @@ -44,6 +44,7 @@ export function WSProvider({url, onmessage, children}) { const {is_authenticated} = useAuth() const [isReady, setIsReady] = useState(false) const [doReconnect, setDoReconnect] = useState(false) + const [welcomeData, setWelcomeData] = useState({name: "", perm: "", show_blason: true, show_flag: false}) const [state, dispatch] = useReducer(reducer, {listener: []}) const ws = useRef(null) const listenersRef = useRef([]) @@ -58,6 +59,15 @@ export function WSProvider({url, onmessage, children}) { listenersRef.current = state.listener }, [state.listener]) + const welcomeListener = ({data}) => { + setWelcomeData({ + name: data.name, + perm: data.perm, + show_blason: data.show_blason, + show_flag: data.show_flag + }) + } + useEffect(() => { if (!doReconnect && !is_authenticated && isReady) return; @@ -73,7 +83,7 @@ export function WSProvider({url, onmessage, children}) { newSocket.onclose = ws.current.onclose newSocket.onmessage = ws.current.onmessage ws.current = newSocket - }catch (e) { + } catch (e) { } }, 5000); @@ -87,7 +97,7 @@ export function WSProvider({url, onmessage, children}) { setDoReconnect(true) console.log(`WSProvider ${id} mounted ${mountCounter[id]} time(s)`); - if (mountCounter[id] === 1 && (ws.current === null || ws.current.readyState >= WebSocket.CLOSING)){ + if (mountCounter[id] === 1 && (ws.current === null || ws.current.readyState >= WebSocket.CLOSING)) { console.log("WSProvider: connecting to", url); const socket = new WebSocket(url) @@ -122,6 +132,12 @@ export function WSProvider({url, onmessage, children}) { console.error("Listener callback error:", err) } }); + + if (msg.code === 'welcomeInfo') { + welcomeListener({...msg}) + isHandled = true; + } + if (!isHandled && onmessage) onmessage(JSON.parse(event.data)) } @@ -170,7 +186,7 @@ export function WSProvider({url, onmessage, children}) { } } - console.log("WSProvider: sending message", {uuid, code, type, data}); + //console.log("WSProvider: sending message", {uuid, code, type, data}); ws.current?.send(JSON.stringify({ uuid: uuid, code: code, @@ -183,7 +199,7 @@ export function WSProvider({url, onmessage, children}) { }) => { if (isReadyRef.current) { send2(uuid, code, type, data, resolve, reject); - }else { + } else { let counter = 0; const waitInterval = setInterval(() => { if (isReadyRef.current) { @@ -200,18 +216,19 @@ export function WSProvider({url, onmessage, children}) { } - const ret = {isReady, dispatch, send, wait_length: callbackRef} + const ret = {isReady, dispatch, send, wait_length: callbackRef, welcomeData} return {children} } export function useWS() { - const {isReady, dispatch, send, wait_length} = useContext(WebsocketContext) + const {isReady, dispatch, send, wait_length, welcomeData} = useContext(WebsocketContext) return { dispatch, isReady, wait_length, + welcomeData, sendRequest: (code, data) => { return new Promise((resolve, reject) => { send(uuidv4(), code, "REQUEST", data, resolve, reject); @@ -255,7 +272,7 @@ export function useRequestWS(code, payload, setLoading = null, loadingLevel = 1) useEffect(() => { if (isReady) refresh(code, payload) - else{ + else { if (setLoading) setLoading(loadingLevel) setTimeout(() => refresh(code, payload), 1000) diff --git a/src/main/webapp/src/pages/competition/editor/CMTable.jsx b/src/main/webapp/src/pages/competition/editor/CMTable.jsx index 287b77e..f0d6980 100644 --- a/src/main/webapp/src/pages/competition/editor/CMTable.jsx +++ b/src/main/webapp/src/pages/competition/editor/CMTable.jsx @@ -1,5 +1,5 @@ import React, {useEffect, useRef, useState} from "react"; -import {useRequestWS} from "../../../hooks/useWS.jsx"; +import {useRequestWS, useWS} from "../../../hooks/useWS.jsx"; import {useCombs, useCombsDispatch} from "../../../hooks/useComb.jsx"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {createPortal} from "react-dom"; @@ -13,7 +13,6 @@ import {CategorieSelect} from "./CMTMatchPanel.jsx"; import {PointPanel} from "./CMTPoint.jsx"; import {importOBSConfiguration, OBSProvider, useOBS} from "../../../hooks/useOBS.jsx"; import {SimpleIconsOBS} from "../../../assets/SimpleIconsOBS.ts"; -import {timePrint} from "../../../utils/Tools.js"; import {toast} from "react-toastify"; export function CMTable() { @@ -235,6 +234,7 @@ function ObsAutoSyncWhitPubAff() { const {connected, setText, setTextAndColor, setDiapo} = useOBS(); const oldState = useRef({timeColor: "#000000", timeStr: "--:--", c1: null, c2: null, showScore: true, scoreRouge: 0, scoreBleu: 0}); const state = usePubAffState(); + const {welcomeData} = useWS(); const {getComb} = useCombs(); useEffect(() => { @@ -242,8 +242,8 @@ function ObsAutoSyncWhitPubAff() { const comb = getComb(state.c1); setText("comb.rouge", comb ? (comb?.fname + " " + comb?.lname) : ""); const files = [] - if (comb?.club_uuid) files.push(`club_${comb.club_uuid}.png`) - if (comb?.country) files.push(`flag_${comb.country.toLowerCase()}.png`) + if (comb?.club_uuid && welcomeData.show_blason) files.push(`club_${comb.club_uuid}.png`) + if (comb?.country && welcomeData.show_flag) files.push(`flag_${comb.country.toLowerCase()}.png`) setDiapo("img.rouge", files); oldState.current.c1 = state.c1; } @@ -252,8 +252,8 @@ function ObsAutoSyncWhitPubAff() { const comb = getComb(state.c2); setText("comb.blue", comb ? (comb?.fname + " " + comb?.lname) : ""); const files = [] - if (comb?.club_uuid) files.push(`club_${comb.club_uuid}.png`) - if (comb?.country) files.push(`flag_${comb.country.toLowerCase()}.png`) + if (comb?.club_uuid && welcomeData.show_blason) files.push(`club_${comb.club_uuid}.png`) + if (comb?.country && welcomeData.show_flag) files.push(`flag_${comb.country.toLowerCase()}.png`) setDiapo("img.blue", files); oldState.current.c2 = state.c2; } diff --git a/src/main/webapp/src/pages/competition/editor/CompetitionManagerRoot.jsx b/src/main/webapp/src/pages/competition/editor/CompetitionManagerRoot.jsx index 59e7c3c..2a535e5 100644 --- a/src/main/webapp/src/pages/competition/editor/CompetitionManagerRoot.jsx +++ b/src/main/webapp/src/pages/competition/editor/CompetitionManagerRoot.jsx @@ -75,9 +75,8 @@ function HomeComp() { } function WSStatus({setPerm}) { - const [name, setName] = useState("") const [inWait, setInWait] = useState(false) - const {isReady, wait_length, dispatch} = useWS(); + const {isReady, wait_length, welcomeData} = useWS(); useEffect(() => { const timer = setInterval(() => { @@ -87,16 +86,11 @@ function WSStatus({setPerm}) { }, []); useEffect(() => { - const welcomeListener = ({data}) => { - setName(data.name) - setPerm(data.perm) - } - dispatch({type: 'addListener', payload: {callback: welcomeListener, code: 'welcomeInfo'}}) - return () => dispatch({type: 'removeListener', payload: welcomeListener}) - }, []) + setPerm(welcomeData.perm) + }, [welcomeData]) return
-

{name}

+

{welcomeData.name}

Serveur:
diff --git a/src/main/webapp/src/pages/competition/editor/PubAffWindow.jsx b/src/main/webapp/src/pages/competition/editor/PubAffWindow.jsx index 0b7273d..3b8cd31 100644 --- a/src/main/webapp/src/pages/competition/editor/PubAffWindow.jsx +++ b/src/main/webapp/src/pages/competition/editor/PubAffWindow.jsx @@ -2,6 +2,7 @@ import {useCombs} from "../../../hooks/useComb.jsx"; import {usePubAffState} from "../../../hooks/useExternalWindow.jsx"; import {SmartLogoBackgroundMemo} from "../../../components/SmartLogoBackground.jsx"; import {useMemo, useRef} from 'react'; +import {useWS} from "../../../hooks/useWS.jsx"; const vite_url = import.meta.env.VITE_URL; @@ -124,6 +125,7 @@ const logoStyle = {width: "6vw", height: "min(11vh, 6vw)", objectFit: "contain", function CombDisplay({combId, background, children}) { const {getComb} = useCombs(); const comb = getComb(combId, ""); + const {welcomeData} = useWS(); const logoAlt = useMemo(() => { return comb?.club_str @@ -142,10 +144,11 @@ function CombDisplay({combId, background, children}) { alignItems: "center", }}> {comb !== "" && <> - + {welcomeData.show_blason && }
{comb.fname} {comb.lname}
- {comb.country} + {welcomeData.show_flag ? {comb.country} + :
} }
{children}