mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-08 08:34:20 +02:00
Rename JavGame to Game because all games are not from or at Jav
This commit is contained in:
parent
57057780d8
commit
ed8f20072f
@ -5,15 +5,15 @@ import { render } from "@testing-library/react"
|
||||
import { MemoryRouter } from "react-router-dom"
|
||||
|
||||
import mockStore from "../../../utils/mockStore"
|
||||
import JavGameList from "../index"
|
||||
import GameList from "../index"
|
||||
|
||||
describe("<List />", () => {
|
||||
const renderHelper = (reducer = { readyStatus: "idle" }) => {
|
||||
const { dispatch, ProviderWithStore } = mockStore({ javGameList: reducer })
|
||||
const { dispatch, ProviderWithStore } = mockStore({ gameList: reducer })
|
||||
const { container } = render(
|
||||
<ProviderWithStore>
|
||||
<MemoryRouter>
|
||||
<JavGameList ids={[5]} />
|
||||
<GameList ids={[5]} />
|
||||
</MemoryRouter>
|
||||
</ProviderWithStore>
|
||||
)
|
||||
@ -39,9 +39,6 @@ describe("<List />", () => {
|
||||
bggPhoto:
|
||||
"https://cf.geekdo-images.com/thumb/img/lzczxR5cw7an7tRWeHdOrRtLyes=/fit-in/200x150/pic772547.jpg",
|
||||
bggId: 432,
|
||||
copies: 1,
|
||||
lendAvailability: 1,
|
||||
notStored: 0,
|
||||
ean: "3421272101313",
|
||||
},
|
||||
},
|
@ -2,7 +2,7 @@
|
||||
|
||||
exports[`<List /> renders 1`] = `
|
||||
<div
|
||||
class="JavGameList"
|
||||
class="GameList"
|
||||
>
|
||||
<h4>
|
||||
Jeux JAV
|
@ -10,14 +10,14 @@ interface Props {
|
||||
ids: EntityId[]
|
||||
}
|
||||
|
||||
const JavGameList = ({ ids }: Props) => {
|
||||
const { entities: jeuxJav } = useSelector((state: AppState) => state.javGameList, shallowEqual)
|
||||
const GameList = ({ ids }: Props) => {
|
||||
const { entities: jeux } = useSelector((state: AppState) => state.gameList, shallowEqual)
|
||||
return (
|
||||
<div className={styles.JavGameList}>
|
||||
<div className={styles.GameList}>
|
||||
<h4>Jeux JAV</h4>
|
||||
<ul>
|
||||
{ids.map((id) => {
|
||||
const jeu = jeuxJav[id]
|
||||
const jeu = jeux[id]
|
||||
if (!jeu) {
|
||||
return <li key={id}>Le jeu #{id} n'existe pas</li>
|
||||
}
|
||||
@ -33,4 +33,4 @@ const JavGameList = ({ ids }: Props) => {
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(JavGameList)
|
||||
export default memo(GameList)
|
@ -1,6 +1,6 @@
|
||||
@import "../../theme/variables";
|
||||
|
||||
.JavGameList {
|
||||
.GameList {
|
||||
color: $color-white;
|
||||
|
||||
ul {
|
@ -1,6 +1,6 @@
|
||||
import AnnouncementLink from "./AnnouncementLink"
|
||||
import ErrorBoundary from "./ErrorBoundary"
|
||||
import JavGameList from "./JavGameList"
|
||||
import GameList from "./GameList"
|
||||
import Loading from "./Loading"
|
||||
import LoginForm from "./LoginForm"
|
||||
import Notifications, { fetchFor as fetchForNotifications } from "./Notifications"
|
||||
@ -16,7 +16,7 @@ import WishAdd from "./WishAdd"
|
||||
export {
|
||||
AnnouncementLink,
|
||||
ErrorBoundary,
|
||||
JavGameList,
|
||||
GameList,
|
||||
Loading,
|
||||
LoginForm,
|
||||
Notifications,
|
||||
|
@ -4,9 +4,9 @@ import { useDispatch, useSelector, shallowEqual } from "react-redux"
|
||||
import { Helmet } from "react-helmet"
|
||||
|
||||
import { AppDispatch, AppState, AppThunk, EntitiesRequest } from "../../store"
|
||||
import { fetchJavGameListIfNeed } from "../../store/javGameList"
|
||||
import { fetchGameListIfNeed } from "../../store/gameList"
|
||||
import { fetchWishListIfNeed } from "../../store/wishList"
|
||||
import { JavGameList, WishAdd } from "../../components"
|
||||
import { GameList, WishAdd } from "../../components"
|
||||
import styles from "./styles.module.scss"
|
||||
|
||||
export type Props = RouteComponentProps
|
||||
@ -30,7 +30,7 @@ function useList<Entity>(
|
||||
|
||||
if (readyStatus === "failure") return <p>Oops, Failed to load list!</p>
|
||||
|
||||
return <JavGameList ids={ids} />
|
||||
return <GameList ids={ids} />
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ const Wish: FC<Props> = (): JSX.Element => {
|
||||
<Helmet title="Wish" />
|
||||
<WishAdd dispatch={dispatch} />
|
||||
{/* {useList((state: AppState) => state.wishList, fetchWishListifNeed)()} */}
|
||||
{useList((state: AppState) => state.javGameList, fetchJavGameListIfNeed)()}
|
||||
{useList((state: AppState) => state.gameList, fetchGameListIfNeed)()}
|
||||
{/* <button type="button" onClick={() => setList([{id: 3, joueurs: 4, duree: 5, description: "abcd"}])}>
|
||||
Set list!
|
||||
</button> */}
|
||||
@ -50,6 +50,6 @@ const Wish: FC<Props> = (): JSX.Element => {
|
||||
}
|
||||
|
||||
// Fetch server-side data here
|
||||
export const loadData = (): AppThunk[] => [fetchWishListIfNeed(), fetchJavGameListIfNeed()]
|
||||
export const loadData = (): AppThunk[] => [fetchWishListIfNeed(), fetchGameListIfNeed()]
|
||||
|
||||
export default memo(Wish)
|
||||
|
13
src/server/gsheets/games.ts
Normal file
13
src/server/gsheets/games.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import ExpressAccessors from "./expressAccessors"
|
||||
import { Game, GameWithoutId, translationGame } from "../../services/games"
|
||||
|
||||
const expressAccessor = new ExpressAccessors<GameWithoutId, Game>(
|
||||
"Games",
|
||||
new Game(),
|
||||
translationGame
|
||||
)
|
||||
|
||||
export const gameListGet = expressAccessor.listGet()
|
||||
export const gameGet = expressAccessor.get()
|
||||
export const gameAdd = expressAccessor.add()
|
||||
export const gameSet = expressAccessor.set()
|
@ -1,13 +0,0 @@
|
||||
import ExpressAccessors from "./expressAccessors"
|
||||
import { JavGame, JavGameWithoutId, translationJavGame } from "../../services/javGames"
|
||||
|
||||
const expressAccessor = new ExpressAccessors<JavGameWithoutId, JavGame>(
|
||||
"JavGames",
|
||||
new JavGame(),
|
||||
translationJavGame
|
||||
)
|
||||
|
||||
export const javGameListGet = expressAccessor.listGet()
|
||||
export const javGameGet = expressAccessor.get()
|
||||
export const javGameAdd = expressAccessor.add()
|
||||
export const javGameSet = expressAccessor.set()
|
@ -12,7 +12,7 @@ const ANONYMIZED_DB_PATH = path.resolve(process.cwd(), "access/dbAnonymized.json
|
||||
export class SheetNames {
|
||||
Announcements = "Annonces"
|
||||
|
||||
JavGames = "Jeux JAV"
|
||||
Games = "Jeux"
|
||||
|
||||
PreVolunteers = "PreMembres"
|
||||
|
||||
|
@ -18,7 +18,7 @@ import ssr from "./ssr"
|
||||
import certbotRouter from "../routes/certbot"
|
||||
import { hasSecret, secure } from "./secure"
|
||||
import { announcementListGet } from "./gsheets/announcements"
|
||||
import { javGameListGet } from "./gsheets/javGames"
|
||||
import { gameListGet } from "./gsheets/games"
|
||||
import { preVolunteerAdd, preVolunteerCountGet } from "./gsheets/preVolunteers"
|
||||
import { teamListGet } from "./gsheets/teams"
|
||||
import {
|
||||
@ -79,7 +79,7 @@ app.get(
|
||||
* APIs
|
||||
*/
|
||||
// Google Sheets API
|
||||
app.get("/JavGameListGet", javGameListGet)
|
||||
app.get("/GameListGet", gameListGet)
|
||||
app.get("/WishListGet", wishListGet)
|
||||
app.post("/WishAdd", wishAdd)
|
||||
app.post("/PreVolunteerAdd", preVolunteerAdd)
|
||||
|
@ -1,4 +1,4 @@
|
||||
export class JavGame {
|
||||
export class Game {
|
||||
id = 0
|
||||
|
||||
title = ""
|
||||
@ -19,18 +19,12 @@ export class JavGame {
|
||||
|
||||
bggId = 0
|
||||
|
||||
copies = 1
|
||||
|
||||
lendAvailability = 0
|
||||
|
||||
notStored = 0
|
||||
|
||||
ean = ""
|
||||
|
||||
bggPhoto = ""
|
||||
}
|
||||
|
||||
export const translationJavGame: { [k in keyof JavGame]: string } = {
|
||||
export const translationGame: { [k in keyof Game]: string } = {
|
||||
id: "id",
|
||||
title: "titre",
|
||||
author: "auteur",
|
||||
@ -41,13 +35,10 @@ export const translationJavGame: { [k in keyof JavGame]: string } = {
|
||||
type: "type",
|
||||
poufpaf: "poufpaf",
|
||||
bggId: "bggId",
|
||||
copies: "exemplaires",
|
||||
lendAvailability: "dispoPret",
|
||||
notStored: "nonRangee",
|
||||
ean: "ean",
|
||||
bggPhoto: "bggPhoto",
|
||||
}
|
||||
|
||||
export const elementName = "JavGame"
|
||||
export const elementName = "Game"
|
||||
|
||||
export type JavGameWithoutId = Omit<JavGame, "id">
|
||||
export type GameWithoutId = Omit<Game, "id">
|
9
src/services/gamesAccessors.ts
Normal file
9
src/services/gamesAccessors.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import ServiceAccessors from "./accessors"
|
||||
import { elementName, Game, GameWithoutId } from "./games"
|
||||
|
||||
const serviceAccessors = new ServiceAccessors<GameWithoutId, Game>(elementName)
|
||||
|
||||
export const gameListGet = serviceAccessors.listGet()
|
||||
export const gameGet = serviceAccessors.get()
|
||||
export const gameAdd = serviceAccessors.add()
|
||||
export const gameSet = serviceAccessors.set()
|
@ -1,9 +0,0 @@
|
||||
import ServiceAccessors from "./accessors"
|
||||
import { elementName, JavGame, JavGameWithoutId } from "./javGames"
|
||||
|
||||
const serviceAccessors = new ServiceAccessors<JavGameWithoutId, JavGame>(elementName)
|
||||
|
||||
export const javGameListGet = serviceAccessors.listGet()
|
||||
export const javGameGet = serviceAccessors.get()
|
||||
export const javGameAdd = serviceAccessors.add()
|
||||
export const javGameSet = serviceAccessors.set()
|
@ -2,18 +2,18 @@ import axios from "axios"
|
||||
import _ from "lodash"
|
||||
|
||||
import mockStore from "../../utils/mockStore"
|
||||
import JavGameList, {
|
||||
import GameList, {
|
||||
initialState,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
fetchJavGameList,
|
||||
} from "../javGameList"
|
||||
import { JavGame } from "../../services/javGames"
|
||||
fetchGameList,
|
||||
} from "../gameList"
|
||||
import { Game } from "../../services/games"
|
||||
|
||||
jest.mock("axios")
|
||||
|
||||
const mockData: JavGame[] = [
|
||||
const mockData: Game[] = [
|
||||
{
|
||||
id: 5,
|
||||
title: "6 qui prend!",
|
||||
@ -27,22 +27,19 @@ const mockData: JavGame[] = [
|
||||
bggPhoto:
|
||||
"https://cf.geekdo-images.com/thumb/img/lzczxR5cw7an7tRWeHdOrRtLyes=/fit-in/200x150/pic772547.jpg",
|
||||
bggId: 432,
|
||||
copies: 1,
|
||||
lendAvailability: 1,
|
||||
notStored: 0,
|
||||
ean: "3421272101313",
|
||||
},
|
||||
]
|
||||
const mockError = "Oops! Something went wrong."
|
||||
|
||||
describe("JavGameList reducer", () => {
|
||||
describe("GameList reducer", () => {
|
||||
it("should handle initial state", () => {
|
||||
// @ts-expect-error
|
||||
expect(JavGameList(undefined, {})).toEqual(initialState)
|
||||
expect(GameList(undefined, {})).toEqual(initialState)
|
||||
})
|
||||
|
||||
it("should handle requesting correctly", () => {
|
||||
expect(JavGameList(undefined, { type: getRequesting.type })).toEqual({
|
||||
expect(GameList(undefined, { type: getRequesting.type })).toEqual({
|
||||
readyStatus: "request",
|
||||
ids: [],
|
||||
entities: {},
|
||||
@ -50,7 +47,7 @@ describe("JavGameList reducer", () => {
|
||||
})
|
||||
|
||||
it("should handle success correctly", () => {
|
||||
expect(JavGameList(undefined, { type: getSuccess.type, payload: mockData })).toEqual({
|
||||
expect(GameList(undefined, { type: getSuccess.type, payload: mockData })).toEqual({
|
||||
...initialState,
|
||||
readyStatus: "success",
|
||||
ids: _.map(mockData, "id"),
|
||||
@ -59,7 +56,7 @@ describe("JavGameList reducer", () => {
|
||||
})
|
||||
|
||||
it("should handle failure correctly", () => {
|
||||
expect(JavGameList(undefined, { type: getFailure.type, payload: mockError })).toEqual({
|
||||
expect(GameList(undefined, { type: getFailure.type, payload: mockError })).toEqual({
|
||||
...initialState,
|
||||
readyStatus: "failure",
|
||||
error: mockError,
|
||||
@ -67,8 +64,8 @@ describe("JavGameList reducer", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("JavGameList action", () => {
|
||||
it("fetches JavGame list successful", async () => {
|
||||
describe("GameList action", () => {
|
||||
it("fetches Game list successful", async () => {
|
||||
const { dispatch, getActions } = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: getRequesting.type, payload: undefined },
|
||||
@ -78,11 +75,11 @@ describe("JavGameList action", () => {
|
||||
// @ts-expect-error
|
||||
axios.get.mockResolvedValue({ data: mockData })
|
||||
|
||||
await dispatch(fetchJavGameList())
|
||||
await dispatch(fetchGameList())
|
||||
expect(getActions()).toEqual(expectedActions)
|
||||
})
|
||||
|
||||
it("fetches JavGame list failed", async () => {
|
||||
it("fetches Game list failed", async () => {
|
||||
const { dispatch, getActions } = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: getRequesting.type },
|
||||
@ -92,7 +89,7 @@ describe("JavGameList action", () => {
|
||||
// @ts-expect-error
|
||||
axios.get.mockRejectedValue({ message: mockError })
|
||||
|
||||
await dispatch(fetchJavGameList())
|
||||
await dispatch(fetchGameList())
|
||||
expect(getActions()).toEqual(expectedActions)
|
||||
})
|
||||
})
|
||||
|
49
src/store/gameList.ts
Normal file
49
src/store/gameList.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { Game } from "../services/games"
|
||||
import { AppThunk, AppState } from "."
|
||||
import { gameListGet } from "../services/gamesAccessors"
|
||||
|
||||
const gameAdapter = createEntityAdapter<Game>()
|
||||
|
||||
export const initialState = gameAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest)
|
||||
|
||||
const gameList = createSlice({
|
||||
name: "gameList",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Game[]>) => {
|
||||
state.readyStatus = "success"
|
||||
gameAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default gameList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = gameList.actions
|
||||
|
||||
export const fetchGameList = elementListFetch(
|
||||
gameListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des jeux JAV: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchGameList = (state: AppState) => state.gameList.readyStatus !== "success"
|
||||
|
||||
export const fetchGameListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchGameList(getState())) return dispatch(fetchGameList())
|
||||
|
||||
return null
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { JavGame } from "../services/javGames"
|
||||
import { AppThunk, AppState } from "."
|
||||
import { javGameListGet } from "../services/javGamesAccessors"
|
||||
|
||||
const javGameAdapter = createEntityAdapter<JavGame>()
|
||||
|
||||
export const initialState = javGameAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest)
|
||||
|
||||
const javGameList = createSlice({
|
||||
name: "javGameList",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<JavGame[]>) => {
|
||||
state.readyStatus = "success"
|
||||
javGameAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default javGameList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = javGameList.actions
|
||||
|
||||
export const fetchJavGameList = elementListFetch(
|
||||
javGameListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des jeux JAV: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchJavGameList = (state: AppState) => state.javGameList.readyStatus !== "success"
|
||||
|
||||
export const fetchJavGameListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchJavGameList(getState())) return dispatch(fetchJavGameList())
|
||||
|
||||
return null
|
||||
}
|
@ -2,7 +2,7 @@ import { History } from "history"
|
||||
import { connectRouter } from "connected-react-router"
|
||||
|
||||
import auth from "./auth"
|
||||
import javGameList from "./javGameList"
|
||||
import gameList from "./gameList"
|
||||
import announcementList from "./announcementList"
|
||||
import preVolunteerAdd from "./preVolunteerAdd"
|
||||
import preVolunteerCount from "./preVolunteerCount"
|
||||
@ -25,7 +25,7 @@ import wishList from "./wishList"
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export default (history: History) => ({
|
||||
auth,
|
||||
javGameList,
|
||||
gameList,
|
||||
announcementList,
|
||||
preVolunteerAdd,
|
||||
preVolunteerCount,
|
||||
|
Loading…
x
Reference in New Issue
Block a user