mirror of
https://github.com/morbalint/kemkas.git
synced 2026-07-17 19:03:46 +00:00
add edition to URL routes
This commit is contained in:
@@ -72,6 +72,7 @@ public class CharacterPersistenceService(
|
||||
Szint = k.Szint,
|
||||
Faj = k.Faj.Convert(),
|
||||
Osztaly = k.Osztaly.Convert(),
|
||||
Edition = "1e"
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
@@ -2,20 +2,23 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace Kemkas.Web.ViewModels;
|
||||
|
||||
public struct CharacterListItemDto
|
||||
public struct CharacterListItemDto()
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public Guid Id { get; set; }
|
||||
public required Guid Id { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
public required string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("szint")]
|
||||
public byte Szint { get; set; }
|
||||
public required byte Szint { get; set; }
|
||||
|
||||
[JsonPropertyName("faj")]
|
||||
public string Faj { get; set; }
|
||||
public required string Faj { get; set; }
|
||||
|
||||
[JsonPropertyName("osztaly")]
|
||||
public string Osztaly { get; set; }
|
||||
public required string Osztaly { get; set; }
|
||||
|
||||
[JsonPropertyName("edition")]
|
||||
public required string Edition { get; set; }
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import './App.css';
|
||||
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 CharacterList from "./first-edition/pages/CharacterList";
|
||||
import ErrorBoundary from "./shared/ErrorBoundary";
|
||||
@@ -12,42 +12,12 @@ import {UserContext, userDefaults} from './shared/contexts/UserContext';
|
||||
import CreateCharacter2E from "./second-edition/pages/CreateCharacter2E";
|
||||
|
||||
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)
|
||||
|
||||
if (fetchedUser.state === "not-started") {
|
||||
setFetchedUser({...fetchedUser, state: "loading"})
|
||||
fetch('api/User/me')
|
||||
fetch(`${window.location.origin}/api/User/me`)
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
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 (
|
||||
<UserContext.Provider value={fetchedUser}>
|
||||
<Header/>
|
||||
|
||||
@@ -8,6 +8,7 @@ export interface CharacterListItemDto {
|
||||
szint: number,
|
||||
faj: Faj,
|
||||
osztaly: Osztaly,
|
||||
edition: "1e" | "2e"
|
||||
}
|
||||
|
||||
function CharacterListItem(props: {
|
||||
@@ -15,7 +16,7 @@ function CharacterListItem(props: {
|
||||
}) {
|
||||
const {character:c} = props
|
||||
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>{FajLabel(c.faj)}</td>
|
||||
<td>{OsztalyLabel(c.osztaly)}</td>
|
||||
|
||||
Reference in New Issue
Block a user