From efbf3f6f51f2e52b0b5691d9fd0f5bb1e40ad564 Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Wed, 6 Sep 2023 11:25:09 +0200 Subject: [PATCH 1/3] Remove getAll endpoint from GameCardsController in order to filter all cards after userId --- README.md | 3 +- .../gamegcards/GameCardsController.java | 6 --- .../backend/gamegcards/GameCardsService.java | 7 +-- .../GameCardsGridIntegrationTest.java | 51 +++++++------------ .../gamegcards/GameCardsGridServiceTest.java | 38 ++++---------- 5 files changed, 31 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index ca65d95..5f3d83e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # KoToKo: Japanese concentration game app -This mobile application is developed 🛠️ as my personal capstone project for [Java Development Bootcamp at neue fische](https://www.neuefische.de/en/bootcamp/java-development) from May to August 2023 (try the latest version 👉 [Kotoko](https://kotoko.de)) +This mobile application is developed 🛠️ as my personal capstone project for [Java Development Bootcamp at neue fische](https://www.neuefische.de/en/bootcamp/java-development) from May to August 2023 (try the latest version 👉 [Kotoko](https://kotoko.de)) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=kohei-s_kotoko-concentration-app-frontend&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=kohei-s_kotoko-concentration-app-frontend) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=kohei-s_kotoko-concentration-app-frontend&metric=coverage)](https://sonarcloud.io/summary/new_code?id=kohei-s_kotoko-concentration-app-frontend) [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=kohei-s_kotoko-concentration-app-frontend&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=kohei-s_kotoko-concentration-app-frontend) \ \ ![KoToKo_ver1](https://github.com/kohei-s/kotoko-concentration-app/assets/82062401/b4132c77-a729-490f-ac6c-150da692cf4d) +(device pixel ratio: 390x844) ## 1. Concept 📱 New concentration game app aims to support learning Japanese for so called [third culture kids](https://en.wikipedia.org/wiki/Third_culture_kid) growing up speaking a different language in kindergarten or school. The name of the app *KoToKO (言と言)* is a neologism that could mean *Word & Word*. ## 2. Problem 😦 diff --git a/backend/src/main/java/de/neuefische/koheis/backend/gamegcards/GameCardsController.java b/backend/src/main/java/de/neuefische/koheis/backend/gamegcards/GameCardsController.java index eb1b58f..effc4b2 100644 --- a/backend/src/main/java/de/neuefische/koheis/backend/gamegcards/GameCardsController.java +++ b/backend/src/main/java/de/neuefische/koheis/backend/gamegcards/GameCardsController.java @@ -18,12 +18,6 @@ public class GameCardsController { this.gameCardsService = gameCardsService; } - @GetMapping("/all") - List getAllGameCards() { - - return gameCardsService.getAllGameCards(); - } - @GetMapping("/myAll") List getAllMyGameCards() { diff --git a/backend/src/main/java/de/neuefische/koheis/backend/gamegcards/GameCardsService.java b/backend/src/main/java/de/neuefische/koheis/backend/gamegcards/GameCardsService.java index 2aa5f43..0db57a4 100644 --- a/backend/src/main/java/de/neuefische/koheis/backend/gamegcards/GameCardsService.java +++ b/backend/src/main/java/de/neuefische/koheis/backend/gamegcards/GameCardsService.java @@ -23,11 +23,6 @@ public class GameCardsService { this.mongoUserService = mongoUserService; } - public List getAllGameCards(){ - - return gameCardsRepository.findAll(); - } - public List getAllMyGameCards() { String username = SecurityContextHolder.getContext().getAuthentication().getName(); String userId = mongoUserService.findUserIdByUsername(username); @@ -42,7 +37,7 @@ public GameCard getGameCardById(String id){ } public List findByCardSetName(String cardSetName){ - List gameCardList = gameCardsRepository.findAll(); + List gameCardList = getAllMyGameCards(); return gameCardList.stream().filter(card -> cardSetName.equals(card.getCardSetName())).toList(); } diff --git a/backend/src/test/java/de/neuefische/koheis/backend/gamegcards/GameCardsGridIntegrationTest.java b/backend/src/test/java/de/neuefische/koheis/backend/gamegcards/GameCardsGridIntegrationTest.java index 6d55934..a95397e 100644 --- a/backend/src/test/java/de/neuefische/koheis/backend/gamegcards/GameCardsGridIntegrationTest.java +++ b/backend/src/test/java/de/neuefische/koheis/backend/gamegcards/GameCardsGridIntegrationTest.java @@ -53,23 +53,6 @@ void setUpUsers() { mongoUserRepository.save(user); } - @DirtiesContext - @Test - @WithMockUser - void whenListEmpty_thenReturnEmptyList() throws Exception { - //WHEN - mockMvc.perform( - MockMvcRequestBuilders.get("/api/game_cards/all") - .with(csrf()) - ) - - //THEN - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().json(""" - [] - """)); - } - @DirtiesContext @Test @WithMockUser (username = "testUsername", password = "testPassword") @@ -155,18 +138,18 @@ void whenGetNotExistingGameCard_thenReturnNotFoundErrorMessage() throws Exceptio void expectTwoDimensionalArrayOfTwentyEightPlayingCards() throws Exception { //GIVEN String size = "small"; - gameCardsRepository.save(new GameCard("01", "♥1", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("012", "♥2", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("03", "♥3", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("04", "♥4", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("05", "♥5", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("06", "♥6", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("07", "♥7", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("08", "♥8", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("09", "♥9", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("10", "♥10", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("11", "♥11", "playing-cards", "testId")); - gameCardsRepository.save(new GameCard("12", "♥12", "playing-cards", "testId")); + gameCardsRepository.save(new GameCard("01", "♥1", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("02", "♥2", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("03", "♥3", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("04", "♥4", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("05", "♥5", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("06", "♥6", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("07", "♥7", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("08", "♥8", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("09", "♥9", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("10", "♥10", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("11", "♥11", "playing-cards", "1")); + gameCardsRepository.save(new GameCard("12", "♥12", "playing-cards", "1")); //WHEN String result = mockMvc.perform( @@ -209,7 +192,7 @@ void whenAddedGameCard_thenReturnGameCard() throws Exception { .andExpect(jsonPath("id").isNotEmpty()) .andExpect(jsonPath("title").value("testTitle")) .andExpect(jsonPath("cardSetName").value("testSet3")) - .andExpect(jsonPath("authorId").isNotEmpty()); + .andExpect(jsonPath("authorId").value("1")); } @DirtiesContext @@ -250,7 +233,7 @@ void whenUpdateExistingGameCard_thenReturnUpdatedGameCard() throws Exception { { "title": "test_updated", "cardSetName": "testSet", - "authorId": "testId" + "authorId": "1" } """) .with(csrf()) @@ -262,7 +245,7 @@ void whenUpdateExistingGameCard_thenReturnUpdatedGameCard() throws Exception { .andExpect(jsonPath("id").value(id)) .andExpect(jsonPath("title").value("test_updated")) .andExpect(jsonPath("cardSetName").value("testSet")) - .andExpect(jsonPath("authorId").value("testId")); + .andExpect(jsonPath("authorId").value("1")); } @DirtiesContext @@ -271,7 +254,7 @@ void whenUpdateExistingGameCard_thenReturnUpdatedGameCard() throws Exception { void whenUpdateNotExistingGameCard_thenReturnNotFoundErrorMessage() throws Exception { //GIVEN String idOfNotExistingGameCard = "012"; - GameCardWithoutId gameCardWithoutId = new GameCardWithoutId("test", "testSet", "testId"); + GameCardWithoutId gameCardWithoutId = new GameCardWithoutId("test", "testSet", "1"); String gameCardJson = objectMapper.writeValueAsString(gameCardWithoutId); //WHEN @@ -324,7 +307,7 @@ void whenDeleteExistingGameCard_thenReturnEmptyList() throws Exception { //THEN mockMvc.perform( - MockMvcRequestBuilders.get("/api/game_cards/all") + MockMvcRequestBuilders.get("/api/game_cards/myAll") .with(csrf()) ).andExpect(status().isOk()) .andExpect(content().json("[]")); diff --git a/backend/src/test/java/de/neuefische/koheis/backend/gamegcards/GameCardsGridServiceTest.java b/backend/src/test/java/de/neuefische/koheis/backend/gamegcards/GameCardsGridServiceTest.java index 1b6504d..0e6494a 100644 --- a/backend/src/test/java/de/neuefische/koheis/backend/gamegcards/GameCardsGridServiceTest.java +++ b/backend/src/test/java/de/neuefische/koheis/backend/gamegcards/GameCardsGridServiceTest.java @@ -37,29 +37,6 @@ class GameCardsGridServiceTest { GameCard gameCard11 = new GameCard("11", "♥11", "1playing-cards", "testId"); GameCard gameCard12 = new GameCard("12", "♥12", "playing-cards", "testId"); - @Test - void getAllGameCards_thenReturnListOfAllGameCards() { - //Given - List allGameCards = List.of( - gameCard1, gameCard2, gameCard3, - gameCard4, gameCard5, gameCard6, - gameCard7, gameCard8, gameCard9, - gameCard10, gameCard11, gameCard12); - - //WHEN - Mockito.when(gameCardsRepository.findAll()) - .thenReturn(allGameCards); - List expected = List.of( - gameCard1, gameCard2, gameCard3, - gameCard4, gameCard5, gameCard6, - gameCard7, gameCard8, gameCard9, - gameCard10, gameCard11, gameCard12); - List actual = gameCardsService.getAllGameCards(); - - //THEN - assertEquals(expected, actual); - } - @Test void getAllMyGameCards_thenReturnListOfAllGameCards() { //Given @@ -126,20 +103,27 @@ void getNotExistingGameCardWithId_thenThrowException() { void generateGameBoardSmallSize_thenReturnTwoDimensionalArrayOfTwelveGameCards() { //Given String id = "012"; - List allGameCards = List.of( + List allMyGameCards = List.of( gameCard1, gameCard2, gameCard3, gameCard4, gameCard5, gameCard6, gameCard7, gameCard8, gameCard9, gameCard10, gameCard11, gameCard12); //WHEN - Mockito.when(gameCardsRepository.findAll()) - .thenReturn(allGameCards); Mockito.when(idService.createRandomId()) .thenReturn(id); + Mockito.when(authentication.getName()) + .thenReturn("testName"); + Mockito.when(securityContext.getAuthentication()) + .thenReturn(authentication); + Mockito.when(mongoUserService.findUserIdByUsername("testName")) + .thenReturn("testId"); + SecurityContextHolder.setContext(securityContext); + Mockito.when(gameCardsRepository.findAllByAuthorId("testId")) + .thenReturn(allMyGameCards); int expectedRow = 3; int expectedColumn = 3; - GameCard[][] actual = gameCardsService.generateGameBoard("small", allGameCards); + GameCard[][] actual = gameCardsService.generateGameBoard("small", allMyGameCards); //THEN assertEquals(expectedRow, actual.length); From 52d1bf67edd1ba4b3d91106412c4932175d7ec82 Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Wed, 6 Sep 2023 21:51:43 +0200 Subject: [PATCH 2/3] Add sample card data --- frontend/src/App.tsx | 49 +++---------------- .../src/Collection/GameCardCollection.tsx | 9 +--- frontend/src/Collection/GameCardSet.ts | 2 +- frontend/src/Collection/GameCardSetTable.tsx | 17 ++++--- frontend/src/Game/FlipCard.tsx | 15 ++---- frontend/src/Game/createGameCardData.ts | 26 +++++----- frontend/src/Game/createGameCards.ts | 13 +---- frontend/src/Game/setPrefix.ts | 21 ++++++++ frontend/src/Setting/Setting.tsx | 3 +- 9 files changed, 63 insertions(+), 92 deletions(-) create mode 100644 frontend/src/Game/setPrefix.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a110fed..e1e3297 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -32,21 +32,16 @@ export default function App() { const [userName, setUserName] = useState("") const [userInfo, setUserInfo] = useState() - const [allGameCards, setAllGameCards] = useState([]); - const [allCardSets, setAllCardSets] = useState([]); const [allMyGameCards, setAllMyGameCards] = useState([]); const [allMyCardSets, setMyAllCardSets] = useState([]); const navigate = useNavigate() useEffect(() => { - getAllSetNamesAndItsCount() getAllMySetNamesAndItsCount() - }, [allGameCards, allMyGameCards]); + }, [allMyGameCards]); useEffect(() => { me() - loadAllGameCards() - getAllSetNamesAndItsCount() loadAllMyGameCards() getAllMySetNamesAndItsCount() }, [userName]); @@ -108,37 +103,6 @@ export default function App() { .catch(console.error) } - function loadAllGameCards() { - axios.get( - "/api/game_cards/all" - ) - .then(response => response.data) - .then(data => { - const responseDataCardList = data - responseDataCardList.reverse() - setAllGameCards(responseDataCardList) - }) - .catch(console.error) - } - - function getAllSetNamesAndItsCount() { - const listAllSetNames = allGameCards.map((card) => card.cardSetName) - const countList: { [key: string]: number } = {}; - for (const item of listAllSetNames) { - if (countList[item]) { - countList[item] += 1; - } else { - countList[item] = 1; - } - } - const filteredList: GameCardSet[] = []; - for (const [key, value] of Object.entries(countList)) { - const newSet: GameCardSet = {name: key, count: value}; - filteredList.push(newSet) - } - setAllCardSets(filteredList) - } - function loadAllMyGameCards() { axios.get( "/api/game_cards/myAll" @@ -167,6 +131,10 @@ export default function App() { const newMySet: GameCardSet = {name: key, count: value, author: userName}; filteredMyList.push(newMySet) } + const kanjiSet: GameCardSet = {name: "kanji", count: 11, author: "sample"}; + const animalSet: GameCardSet = {name: "animal", count: 8, author: "sample"} + filteredMyList.push(kanjiSet) + filteredMyList.push(animalSet) setMyAllCardSets(filteredMyList) } @@ -183,10 +151,7 @@ export default function App() { }> }> }> }> }> + countCardSets={allMyCardSets}/>}> }/> diff --git a/frontend/src/Collection/GameCardCollection.tsx b/frontend/src/Collection/GameCardCollection.tsx index 360f52e..e119621 100644 --- a/frontend/src/Collection/GameCardCollection.tsx +++ b/frontend/src/Collection/GameCardCollection.tsx @@ -8,9 +8,6 @@ import GameCardSetTable from "./GameCardSetTable.tsx"; import {GameCardSet} from "./GameCardSet.ts"; type Props = { - allGameCards: GameCard[] - loadAllGameCards: () => void - allCardSets: GameCardSet[] allMyGameCards: GameCard[] loadAllMyGameCards: () => void allMyCardSets: GameCardSet[] @@ -18,11 +15,9 @@ type Props = { export default function GameCardCollection(props: Props) { - /* - const [, setAllCardSetNames] = useState([]);*/ const [isModalOpen, setIsModalOpen] = useState(false); - if (!props.allGameCards) { + if (!props.allMyGameCards) { return "Loading cards..." } @@ -53,7 +48,7 @@ export default function GameCardCollection(props: Props) { - + ) diff --git a/frontend/src/Collection/GameCardSet.ts b/frontend/src/Collection/GameCardSet.ts index 575c1fa..c8b8749 100644 --- a/frontend/src/Collection/GameCardSet.ts +++ b/frontend/src/Collection/GameCardSet.ts @@ -1,5 +1,5 @@ export type GameCardSet = { name: string, count: number, - author?: string + author: string } \ No newline at end of file diff --git a/frontend/src/Collection/GameCardSetTable.tsx b/frontend/src/Collection/GameCardSetTable.tsx index 4db7f64..92bda2f 100644 --- a/frontend/src/Collection/GameCardSetTable.tsx +++ b/frontend/src/Collection/GameCardSetTable.tsx @@ -7,7 +7,6 @@ import {GameCardSet} from "./GameCardSet.ts"; import {Link} from "react-router-dom"; type Props = { - allCardSets: GameCardSet[], allMyCardSets: GameCardSet[] } export default function GameCardSetTable(props: Props) { @@ -52,16 +51,18 @@ export default function GameCardSetTable(props: Props) { sx={{'&:last-child td, &:last-child th': {border: 0}}} > - {row.name} + {row.name} {((row.name === "kanji")||(row.name === "animal"))? "(sample)": ""} {row.count} - - - - - + {(row.author === "sample") ? "" : + + + + + + } ))} diff --git a/frontend/src/Game/FlipCard.tsx b/frontend/src/Game/FlipCard.tsx index 0ff573e..360eca9 100644 --- a/frontend/src/Game/FlipCard.tsx +++ b/frontend/src/Game/FlipCard.tsx @@ -31,7 +31,9 @@ export default function FlipCard(props: Props) { const [userDiacritics, setUserDiacritics] = useState([]); const loadGameCards = useCallback(() => { - if ((props.gameName === "hiragana") || (props.gameName === "katakana") || (props.gameName === "playing-cards")) { + if ((props.gameName === "hiragana") || (props.gameName === "katakana") || (props.gameName === "playing-cards") + || (props.gameName === "kanji") || (props.gameName === "animal")) + { const cardsData = createGameCards(props.gameName, props.gameSize, userDiacritics); const setId = cardsData.id const cardGridData = {cardsGrid: cardsData.cardGrid} @@ -125,18 +127,11 @@ export default function FlipCard(props: Props) { function renderCardImage(card: GameCard) { if (card.title === "empty") { return start; - } else if (props.gameName === "hiragana" || props.gameName === "katakana" || props.gameName === "playing-cards") { + } else if (props.gameName === "hiragana" || props.gameName === "katakana" || props.gameName === "playing-cards" + || props.gameName === "kanji" || props.gameName === "animal") { const src = `/${props.gameName}-images/${props.gameName}-${card.title}.png`; const alt = `${props.gameName}${card.title}${card.cardSetName}`; return {alt}/; - } else if (props.gameName === "kanji") { - const src = `/${props.gameName}-images/${props.gameName}-${card.title.slice(2)}.png`; - const alt = `${props.gameName}${card.title.slice(2)}${card.cardSetName}`; - return {alt}/; - } else if (props.gameName === "animal") { - const src = `/${props.gameName}-images/${props.gameName}-${card.title.split(" ")[1]}.png`; - const alt = `${props.gameName}${card.title.split(" ")[1]}${card.cardSetName}`; - return {alt}/; } else { return card.title; } diff --git a/frontend/src/Game/createGameCardData.ts b/frontend/src/Game/createGameCardData.ts index 65c7da2..803cc88 100644 --- a/frontend/src/Game/createGameCardData.ts +++ b/frontend/src/Game/createGameCardData.ts @@ -1,4 +1,5 @@ import {GameCard} from "./GameCard.ts"; +import setPrefix from "./setPrefix.ts"; export default function createGameCardData(setName: string, diacritics: boolean[]) { @@ -45,26 +46,29 @@ export default function createGameCardData(setName: string, diacritics: boolean[ "club-8", "club-9", "club-10", "club-11", "club-12", "club-13" ] + const kanjiReading: string[] = [ + "ha", "ko", "ie", "inu", "mori", "mizu", "toki", "hi", "hana", "hito", "sora" + ] + + const animalReading: string[] = [ + "inu", "hato", "kirin", "neko", "pengin", "raion", "tora", "zou" + ] + + let listData: string[]; if ((setName === "hiragana" && diacritics[0]) || (setName === "katakana" && diacritics[1])){ listData = alphabetReading.concat(diacriticsReading) } else if ((setName === "hiragana" && (!diacritics[0])) || (setName === "katakana" && (!diacritics[1]))) { listData = alphabetReading; + } else if (setName === "kanji") { + listData = kanjiReading; + } else if (setName === "animal") { + listData = animalReading; } else { listData = playingCards; } - let prefix: string; - switch (setName) { - case "hiragana": - prefix = "h"; - break; - case "katakana": - prefix = "k"; - break; - default: - prefix = "c"; - } + const prefix: string = setPrefix(setName); const kanaCards: GameCard[] = []; let index = 1; diff --git a/frontend/src/Game/createGameCards.ts b/frontend/src/Game/createGameCards.ts index edcb32a..3d87f1c 100644 --- a/frontend/src/Game/createGameCards.ts +++ b/frontend/src/Game/createGameCards.ts @@ -1,5 +1,6 @@ import {GameCard} from "./GameCard.ts"; import createGameCardData from "./createGameCardData.ts"; +import setPrefix from "./setPrefix.ts"; export function createGameCards(setName: string, gameSize: string, diacritics: boolean[]) { @@ -32,17 +33,7 @@ export function createGameCards(setName: string, gameSize: string, diacritics: b pairing = 8; } - let prefix: string; - switch (setName) { - case "hiragana": - prefix = "h"; - break; - case "katakana": - prefix = "k"; - break; - default: - prefix = "c"; - } + const prefix: string = setPrefix(setName); const cardPairs: GameCard [] = kanaCards.splice(0, pairing); cardPairs.push(...cardPairs.map(card => ({...card}))); diff --git a/frontend/src/Game/setPrefix.ts b/frontend/src/Game/setPrefix.ts new file mode 100644 index 0000000..808b019 --- /dev/null +++ b/frontend/src/Game/setPrefix.ts @@ -0,0 +1,21 @@ +export default function setPrefix(setName: string) { + let prefix: string; + switch (setName) { + case "hiragana": + prefix = "h"; + break; + case "katakana": + prefix = "k"; + break; + case "kanji": + prefix = "kan"; + break; + case "animal": + prefix = "an"; + break; + default: + prefix = "c"; + } + + return prefix; +} diff --git a/frontend/src/Setting/Setting.tsx b/frontend/src/Setting/Setting.tsx index eb031c8..3139679 100644 --- a/frontend/src/Setting/Setting.tsx +++ b/frontend/src/Setting/Setting.tsx @@ -121,7 +121,6 @@ export default function Setting(props: Props) { selectedCardSet: selectedCustomGame } props.update(updatedUserInfo) - } function setUserDiacriticsText(index: number) { @@ -213,7 +212,7 @@ export default function Setting(props: Props) { .map(setName => {setName.name} ({setName.count}))} + >{setName.name} {((setName.name === "kanji")||(setName.name === "animal"))? "(sample)" : "(" + setName.count.toString() + ")"})} current set: {selectedCustomGame} From 8f0f0bb95af965681ea993a2b389a9fcfe65cb23 Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Thu, 7 Sep 2023 11:58:15 +0200 Subject: [PATCH 3/3] Add sample games, modify edit and setting components accordingly --- frontend/src/App.tsx | 1 + frontend/src/Collection/GameCardSet.ts | 2 +- frontend/src/Collection/GameCardSetTable.tsx | 2 +- frontend/src/Edit/EditGameCard.tsx | 10 ++++++++-- frontend/src/Game/GameBoard.ts | 17 +++++++---------- frontend/src/Setting/Setting.tsx | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index e1e3297..e73498e 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -156,6 +156,7 @@ export default function App() { allMyCardSets={allMyCardSets}/>}> }> }> ) -} \ No newline at end of file +} diff --git a/frontend/src/Edit/EditGameCard.tsx b/frontend/src/Edit/EditGameCard.tsx index 1876fb2..2a82b98 100644 --- a/frontend/src/Edit/EditGameCard.tsx +++ b/frontend/src/Edit/EditGameCard.tsx @@ -6,9 +6,11 @@ import NewGameCard from "../Collection/NewGameCard.tsx"; import {useState} from "react"; import "./EditGameCard.css" import {useParams} from "react-router-dom"; +import {GameCardSet} from "../Collection/GameCardSet.ts"; type Props = { allMyGameCards: GameCard[] + allMyCardSets: GameCardSet[] loadAllMyGameCards: () => void } @@ -17,6 +19,8 @@ export default function EditGameCard(props: Props) { const params = useParams() const setName: string = params.setName as string const number: string = params.number as string + const actualCardSet: GameCardSet = props.allMyCardSets.find(cardSet => cardSet.name === setName) as GameCardSet + const actualNumber: string = actualCardSet.count.toString() const [isAddModalOpen, setIsAddModalOpen] = useState(false); @@ -28,6 +32,7 @@ export default function EditGameCard(props: Props) { setIsAddModalOpen(false) } + return ( <>
@@ -35,7 +40,8 @@ export default function EditGameCard(props: Props) { alt={"edit-logo"}/>
- Name: {setName}
Number: {number} + Name: {setName} +
Number: {(actualNumber === number) ? number : actualNumber} @@ -59,4 +65,4 @@ export default function EditGameCard(props: Props) { ) -} \ No newline at end of file +} diff --git a/frontend/src/Game/GameBoard.ts b/frontend/src/Game/GameBoard.ts index 93c2762..23fe263 100644 --- a/frontend/src/Game/GameBoard.ts +++ b/frontend/src/Game/GameBoard.ts @@ -3,8 +3,8 @@ import {useParams} from "react-router-dom"; import {UserInfo} from "../Security/UserInfo.ts"; type Props = { - userInfo: UserInfo| undefined - update: (userInfo:UserInfo) => void + userInfo: UserInfo | undefined + update: (userInfo: UserInfo) => void } export default function GameBoard(props: Props) { @@ -12,14 +12,11 @@ export default function GameBoard(props: Props) { const size: string = params.gameSize as string; const name: string = params.gameName as string; - if ((size === "small") || (size === "medium") || (size === "large")) { - if ((name === "hiragana") || (name === "katakana") || (name === "playing-cards") || (name === "animal") || (name === "kanji")) { - - return createGameBoard({gameSize: size, gameName: name, userInfo: props.userInfo, update: props.update}); - } else { - - return ("Invalid parameters!"); - } + try { + return createGameBoard({gameSize: size, gameName: name, userInfo: props.userInfo, update: props.update}); + } catch (e) { + console.log(e) + return ("Invalid parameters!"); } } diff --git a/frontend/src/Setting/Setting.tsx b/frontend/src/Setting/Setting.tsx index 3139679..4a2d9c9 100644 --- a/frontend/src/Setting/Setting.tsx +++ b/frontend/src/Setting/Setting.tsx @@ -212,7 +212,7 @@ export default function Setting(props: Props) { .map(setName => {setName.name} {((setName.name === "kanji")||(setName.name === "animal"))? "(sample)" : "(" + setName.count.toString() + ")"})} + >{setName.name} {"(" + setName.count.toString() + ")"})} current set: {selectedCustomGame}