user_registration #10

Closed
Roflin wants to merge 2 commits from user_registration into main
4 changed files with 15 additions and 15 deletions
Showing only changes of commit 79b7312896 - Show all commits

View File

@ -1,5 +1,5 @@
import './App.css'; import './App.css';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useCallback } from 'react';
import MenuBar from './components/MenuBar'; import MenuBar from './components/MenuBar';
import Login from './components/Login'; import Login from './components/Login';
import Gamenights from './components/Gamenights'; import Gamenights from './components/Gamenights';
@ -68,20 +68,20 @@ function App() {
setFlashData(data); setFlashData(data);
}; };
const refetchGamenights = () => { const refetchGamenights = useCallback(() => {
unpack_api_result(get_gamenights(user.jwt), setFlashData) unpack_api_result(get_gamenights(user.jwt), setFlashData)
.then(result => { .then(result => {
if (result !== undefined) { if (result !== undefined) {
setGamenights(result.gamenights); setGamenights(result.gamenights);
} }
}); });
}; }, [user]);
useEffect(() => { useEffect(() => {
if (appState === 'LoggedIn') { if (appState === 'LoggedIn') {
refetchGamenights() refetchGamenights()
} }
}, [appState]) }, [appState, refetchGamenights])
useEffect(() => { useEffect(() => {
if (appState === 'LoggedIn') { if (appState === 'LoggedIn') {
@ -92,7 +92,7 @@ function App() {
} }
}); });
} }
}, [appState]) }, [appState, user])
useEffect(() => { useEffect(() => {
setUser(JSON.parse(localStorage.getItem(localStorageUserKey))); setUser(JSON.parse(localStorage.getItem(localStorageUserKey)));

View File

@ -1,4 +1,4 @@
import {useState, useEffect} from 'react'; import {useState, useEffect, useCallback} from 'react';
import Checkbox from '@mui/material/Checkbox'; import Checkbox from '@mui/material/Checkbox';
import Table from '@mui/material/Table'; import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody'; import TableBody from '@mui/material/TableBody';
@ -35,7 +35,7 @@ function AdminPanel(props) {
setPage(0); setPage(0);
}; };
const refetchTokens = () => { const refetchTokens = useCallback(() => {
if(props.user !== null) { if(props.user !== null) {
unpack_api_result(get_registration_tokens(props.user.jwt), props.setFlash) unpack_api_result(get_registration_tokens(props.user.jwt), props.setFlash)
.then(result => { .then(result => {
@ -44,7 +44,7 @@ function AdminPanel(props) {
} }
}); });
} }
} }, [props.setFlash, props.user]);
const deleteToken = (id) => { const deleteToken = (id) => {
if(props.user !== null) { if(props.user !== null) {
@ -75,7 +75,7 @@ function AdminPanel(props) {
useEffect(() => { useEffect(() => {
refetchTokens() refetchTokens()
}, []) }, [refetchTokens])
let columns = [ let columns = [
{ {

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useCallback } from 'react';
import List from '@mui/material/List'; import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem'; import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText'; import ListItemText from '@mui/material/ListItemText';
@ -13,10 +13,10 @@ import {unpack_api_result, get_gamenight, patch_gamenight} from '../api/Api';
function Gamenight(props) { function Gamenight(props) {
const [dense, setDense] = useState(true); const dense = true;
const [gamenight, setGamenight] = useState(null); const [gamenight, setGamenight] = useState(null);
const fetchGamenight = () => { const fetchGamenight = useCallback(() => {
if (props.user !== null) { if (props.user !== null) {
unpack_api_result(get_gamenight(props.gamenightId, props.user.jwt), props.setFlash) unpack_api_result(get_gamenight(props.gamenightId, props.user.jwt), props.setFlash)
.then(result => { .then(result => {
@ -25,9 +25,9 @@ function Gamenight(props) {
} }
}); });
} }
} }, [props.gamenightId, props.user, props.setFlash]);
useEffect(fetchGamenight, []); useEffect(fetchGamenight, [fetchGamenight]);
let games = gamenight?.game_list.map(g => let games = gamenight?.game_list.map(g =>
( (

View File

@ -12,7 +12,7 @@ import AddGameNight from './AddGameNight';
import {delete_gamenight, unpack_api_result} from '../api/Api'; import {delete_gamenight, unpack_api_result} from '../api/Api';
function Gamenights(props) { function Gamenights(props) {
const [dense, setDense] = React.useState(false); const dense = true;
const DeleteGamenight = (game_id) => { const DeleteGamenight = (game_id) => {
if (props.user !== null) { if (props.user !== null) {