feat: cm admin comb selector
This commit is contained in:
parent
936392f8bd
commit
00701fb874
@ -12,6 +12,7 @@ import jakarta.inject.Inject;
|
|||||||
import org.hibernate.reactive.mutiny.Mutiny;
|
import org.hibernate.reactive.mutiny.Mutiny;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@WithSession
|
@WithSession
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
@ -22,7 +23,7 @@ public class RRegister {
|
|||||||
CompetitionRepository competitionRepository;
|
CompetitionRepository competitionRepository;
|
||||||
|
|
||||||
@WSReceiver(code = "getRegister", permission = PermLevel.ADMIN)
|
@WSReceiver(code = "getRegister", permission = PermLevel.ADMIN)
|
||||||
public Uni<?> getRegister(WebSocketConnection connection, Object o) {
|
public Uni<List<CombEntity>> getRegister(WebSocketConnection connection, Object o) {
|
||||||
return competitionRepository.find("uuid", connection.pathParam("uuid")).firstResult()
|
return competitionRepository.find("uuid", connection.pathParam("uuid")).firstResult()
|
||||||
.call(cm -> Mutiny.fetch(cm.getInsc()))
|
.call(cm -> Mutiny.fetch(cm.getInsc()))
|
||||||
.call(cm -> Mutiny.fetch(cm.getGuests()))
|
.call(cm -> Mutiny.fetch(cm.getGuests()))
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public class SRegister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Uni<Void> sendRegisterRemove(String uuid, Long combId) {
|
public Uni<Void> sendRegisterRemove(String uuid, Long combId) {
|
||||||
return send(uuid, "sendRegister", combId);
|
return send(uuid, "sendRegisterRemove", combId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uni<Void> send(String uuid, String code, Object data) {
|
public Uni<Void> send(String uuid, String code, Object data) {
|
||||||
|
|||||||
@ -290,7 +290,7 @@ function Modal({sendRegister, modalState, setModalState, source}) {
|
|||||||
const [cat, setCat] = useState(0)
|
const [cat, setCat] = useState(0)
|
||||||
const [gcat, setGCat] = useState("")
|
const [gcat, setGCat] = useState("")
|
||||||
const [club, setClub] = useState("")
|
const [club, setClub] = useState("")
|
||||||
const [country_, setCountry_] = useState("fr")
|
const [country_, setCountry_] = useState("FR")
|
||||||
const [genre, setGenre] = useState("NA")
|
const [genre, setGenre] = useState("NA")
|
||||||
const [editMode, setEditMode] = useState(false)
|
const [editMode, setEditMode] = useState(false)
|
||||||
const [lockEdit, setLockEdit] = useState(false)
|
const [lockEdit, setLockEdit] = useState(false)
|
||||||
@ -307,7 +307,7 @@ function Modal({sendRegister, modalState, setModalState, source}) {
|
|||||||
setLockEdit(false)
|
setLockEdit(false)
|
||||||
setClub("")
|
setClub("")
|
||||||
setGCat("")
|
setGCat("")
|
||||||
setCountry_("fr")
|
setCountry_("FR")
|
||||||
setGenre("NA")
|
setGenre("NA")
|
||||||
} else {
|
} else {
|
||||||
setLicence(modalState.licence ? modalState.licence : "")
|
setLicence(modalState.licence ? modalState.licence : "")
|
||||||
@ -319,7 +319,7 @@ function Modal({sendRegister, modalState, setModalState, source}) {
|
|||||||
setLockEdit(modalState.lockEdit)
|
setLockEdit(modalState.lockEdit)
|
||||||
setClub(modalState.club ? modalState.club.name : "")
|
setClub(modalState.club ? modalState.club.name : "")
|
||||||
setGCat(modalState.categorie ? modalState.categorie : "")
|
setGCat(modalState.categorie ? modalState.categorie : "")
|
||||||
setCountry_(modalState.country ? modalState.country : "fr")
|
setCountry_(modalState.country ? modalState.country : "FR")
|
||||||
setGenre(modalState.genre ? modalState.genre : "NA")
|
setGenre(modalState.genre ? modalState.genre : "NA")
|
||||||
}
|
}
|
||||||
}, [modalState]);
|
}, [modalState]);
|
||||||
|
|||||||
@ -104,8 +104,33 @@ export function CategoryContent({cat, catId, setCat}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function AddComb({groups, setGroups}) {
|
function AddComb({groups, setGroups}) {
|
||||||
const {data} = useRequestWS("getRegister", null)
|
const {data, setData} = useRequestWS("getRegister", null)
|
||||||
const combDispatch = useCombsDispatch();
|
const combDispatch = useCombsDispatch();
|
||||||
|
const {dispatch} = useWS();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const sendRegister = ({data}) => {
|
||||||
|
setData(prev => {
|
||||||
|
if (prev === null)
|
||||||
|
return [data];
|
||||||
|
return [...prev.filter(d => d.id !== data.id), data];
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const sendRegisterRemove = ({data}) => {
|
||||||
|
setData(prev => {
|
||||||
|
if (prev === null)
|
||||||
|
return null;
|
||||||
|
return [...prev.filter(d => d.id !== data)];
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch({type: 'addListener', payload: {callback: sendRegister, code: 'sendRegister'}})
|
||||||
|
dispatch({type: 'addListener', payload: {callback: sendRegisterRemove, code: 'sendRegisterRemove'}})
|
||||||
|
return () => {
|
||||||
|
dispatch({type: 'removeListener', payload: {callback: sendRegister, code: 'sendRegister'}})
|
||||||
|
dispatch({type: 'removeListener', payload: {callback: sendRegisterRemove, code: 'sendRegisterRemove'}})
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data === null)
|
if (data === null)
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import {useCountries} from "../../../hooks/useCountries.jsx";
|
|||||||
import {useEffect, useReducer, useState} from "react";
|
import {useEffect, useReducer, useState} from "react";
|
||||||
import {CatList, getCatName} from "../../../utils/Tools.js";
|
import {CatList, getCatName} from "../../../utils/Tools.js";
|
||||||
import {CombName} from "../../../hooks/useComb.jsx";
|
import {CombName} from "../../../hooks/useComb.jsx";
|
||||||
|
import {useWS} from "../../../hooks/useWS.jsx";
|
||||||
|
|
||||||
function SelectReducer(state, action) {
|
function SelectReducer(state, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@ -40,6 +41,10 @@ function SelectReducer(state, action) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return filteredState2;
|
return filteredState2;
|
||||||
|
case 'REMOVE_ID':
|
||||||
|
const newState2 = {...state};
|
||||||
|
delete newState2[action.payload];
|
||||||
|
return newState2;
|
||||||
case 'REMOVE_ALL':
|
case 'REMOVE_ALL':
|
||||||
return {};
|
return {};
|
||||||
default:
|
default:
|
||||||
@ -49,6 +54,7 @@ function SelectReducer(state, action) {
|
|||||||
|
|
||||||
export function SelectCombModalContent({data, setGroups}) {
|
export function SelectCombModalContent({data, setGroups}) {
|
||||||
const country = useCountries('fr')
|
const country = useCountries('fr')
|
||||||
|
const {dispatch} = useWS()
|
||||||
const [dispo, dispoReducer] = useReducer(SelectReducer, {})
|
const [dispo, dispoReducer] = useReducer(SelectReducer, {})
|
||||||
const [select, selectReducer] = useReducer(SelectReducer, {})
|
const [select, selectReducer] = useReducer(SelectReducer, {})
|
||||||
|
|
||||||
@ -74,7 +80,19 @@ export function SelectCombModalContent({data, setGroups}) {
|
|||||||
dispoReducer({type: 'ADD_ALL', payload: data.map(d => d.id)})
|
dispoReducer({type: 'ADD_ALL', payload: data.map(d => d.id)})
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => { // TODO: add ws listener
|
|
||||||
|
useEffect(() => {
|
||||||
|
const sendRegisterRemove = ({data}) => {
|
||||||
|
dispoReducer({type: 'REMOVE_ID', payload: data})
|
||||||
|
selectReducer({type: 'REMOVE_ID', payload: data})
|
||||||
|
}
|
||||||
|
dispatch({type: 'addListener', payload: {callback: sendRegisterRemove, code: 'sendRegisterRemove'}})
|
||||||
|
return () => {
|
||||||
|
dispatch({type: 'removeListener', payload: {callback: sendRegisterRemove, code: 'sendRegisterRemove'}})
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
if (data == null)
|
if (data == null)
|
||||||
return
|
return
|
||||||
const selectedIds = Object.keys(select).map(g => Number(g))
|
const selectedIds = Object.keys(select).map(g => Number(g))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user