add edition to URL routes

This commit is contained in:
2024-01-18 18:42:36 +01:00
committed by Bálint Mórász
parent e0a4437d43
commit c0459aede2
4 changed files with 62 additions and 44 deletions
@@ -72,6 +72,7 @@ public class CharacterPersistenceService(
Szint = k.Szint, Szint = k.Szint,
Faj = k.Faj.Convert(), Faj = k.Faj.Convert(),
Osztaly = k.Osztaly.Convert(), Osztaly = k.Osztaly.Convert(),
Edition = "1e"
}) })
.ToListAsync(); .ToListAsync();
@@ -2,20 +2,23 @@ using System.Text.Json.Serialization;
namespace Kemkas.Web.ViewModels; namespace Kemkas.Web.ViewModels;
public struct CharacterListItemDto public struct CharacterListItemDto()
{ {
[JsonPropertyName("id")] [JsonPropertyName("id")]
public Guid Id { get; set; } public required Guid Id { get; set; }
[JsonPropertyName("name")] [JsonPropertyName("name")]
public string Name { get; set; } public required string Name { get; set; }
[JsonPropertyName("szint")] [JsonPropertyName("szint")]
public byte Szint { get; set; } public required byte Szint { get; set; }
[JsonPropertyName("faj")] [JsonPropertyName("faj")]
public string Faj { get; set; } public required string Faj { get; set; }
[JsonPropertyName("osztaly")] [JsonPropertyName("osztaly")]
public string Osztaly { get; set; } public required string Osztaly { get; set; }
[JsonPropertyName("edition")]
public required string Edition { get; set; }
} }
+45 -32
View File
@@ -1,7 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import './App.css'; import './App.css';
import {Faro} from "@grafana/faro-web-sdk"; import {Faro} from "@grafana/faro-web-sdk";
import {createBrowserRouter, RouterProvider} from "react-router-dom"; import {createBrowserRouter, redirect, RouterProvider} from "react-router-dom";
import CreateCharacter from "./first-edition/pages/CreateCharacter"; import CreateCharacter from "./first-edition/pages/CreateCharacter";
import CharacterList from "./first-edition/pages/CharacterList"; import CharacterList from "./first-edition/pages/CharacterList";
import ErrorBoundary from "./shared/ErrorBoundary"; import ErrorBoundary from "./shared/ErrorBoundary";
@@ -12,42 +12,12 @@ import {UserContext, userDefaults} from './shared/contexts/UserContext';
import CreateCharacter2E from "./second-edition/pages/CreateCharacter2E"; import CreateCharacter2E from "./second-edition/pages/CreateCharacter2E";
function App(props: {faro?: Faro}) { function App(props: {faro?: Faro}) {
const router = createBrowserRouter([
{
path: "/",
element: <CreateCharacter faro={props.faro} />,
ErrorBoundary: ErrorBoundary,
},
{
path: "/2e",
element: <CreateCharacter2E />,
ErrorBoundary: ErrorBoundary,
},
{
path: "/2e/:id",
element: <CreateCharacter faro={props.faro}/>,
loader: args => fetch(`api/Character/${args.params.id}`),
ErrorBoundary: ErrorBoundary,
},
{
path: "/karaktereim",
element: <CharacterList />,
loader: () => fetch(`api/Character`),
ErrorBoundary: ErrorBoundary,
},
{
path: "/:id",
element: <CreateCharacter faro={props.faro}/>,
loader: args => fetch(`api/Character/${args.params.id}`),
ErrorBoundary: ErrorBoundary,
},
]);
const [fetchedUser, setFetchedUser] = useState(userDefaults) const [fetchedUser, setFetchedUser] = useState(userDefaults)
if (fetchedUser.state === "not-started") { if (fetchedUser.state === "not-started") {
setFetchedUser({...fetchedUser, state: "loading"}) setFetchedUser({...fetchedUser, state: "loading"})
fetch('api/User/me') fetch(`${window.location.origin}/api/User/me`)
.then(response => { .then(response => {
if (response.ok) { if (response.ok) {
return response.text(); return response.text();
@@ -69,6 +39,49 @@ function App(props: {faro?: Faro}) {
}) })
} }
const router = createBrowserRouter([
{
path: "/",
loader: () => fetchedUser.data == null ? redirect("/1e/karakter") : redirect("/karaktereim")
},
{
path: "/karaktereim",
element: <CharacterList />,
loader: () => fetch(`${window.location.origin}/api/Character`),
ErrorBoundary: ErrorBoundary,
},
{
path: "/1e",
loader: () => redirect("/1e/karakter")
},
{
path: "/1e/karakter",
element: <CreateCharacter faro={props.faro} />,
ErrorBoundary: ErrorBoundary,
},
{
path: "/1e/karakter/:id",
element: <CreateCharacter faro={props.faro}/>,
loader: args => fetch(`${window.location.origin}/api/Character/${args.params.id}`),
ErrorBoundary: ErrorBoundary,
},
{
path: "/2e",
loader: () => redirect("/2e/karakter")
},
{
path: "/2e/karakter",
element: <CreateCharacter2E />,
ErrorBoundary: ErrorBoundary,
},
{
path: "/2e/karakter/:id",
element: <CreateCharacter faro={props.faro}/>,
loader: args => fetch(`${window.location.origin}/api/Character/${args.params.id}`),
ErrorBoundary: ErrorBoundary,
},
]);
return ( return (
<UserContext.Provider value={fetchedUser}> <UserContext.Provider value={fetchedUser}>
<Header/> <Header/>
@@ -8,6 +8,7 @@ export interface CharacterListItemDto {
szint: number, szint: number,
faj: Faj, faj: Faj,
osztaly: Osztaly, osztaly: Osztaly,
edition: "1e" | "2e"
} }
function CharacterListItem(props: { function CharacterListItem(props: {
@@ -15,7 +16,7 @@ function CharacterListItem(props: {
}) { }) {
const {character:c} = props const {character:c} = props
return <> return <>
<td><a href={`/${c.id}`}>{c.name}</a></td> <td><a href={`/${c.edition}/karakter/${c.id}`}>{c.name}</a></td>
<td>{c.szint}. szintű</td> <td>{c.szint}. szintű</td>
<td>{FajLabel(c.faj)}</td> <td>{FajLabel(c.faj)}</td>
<td>{OsztalyLabel(c.osztaly)}</td> <td>{OsztalyLabel(c.osztaly)}</td>