1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
import { useContext, useState } from "react";
import { LanguageContext } from "../Locales/Context";
import { BackendURL } from "../Config";
import axios from "axios";
import { RangedWeapon } from "../Models/RangedWeapon";
import { Navigate, useParams } from "react-router";
import { GetLocalizedString } from "../Locales/Locales";
import "./Weapons.css"
const RangedWeaponsURL = `${BackendURL}/weapons/ranged`;
function RangedWeaponPage() {
const { id } = useParams();
const lang = useContext(LanguageContext);
const [weapon, setWeapon] = useState<RangedWeapon | null>(null);
useState(() => {
getWeapon(id).then(data => setWeapon(data));
});
if (weapon == null) {
return <h1> Not found </h1>; // <Navigate to="/404" replace />;
}
return (
<div className="WeaponPage">
<span> <h1> {weapon?.Name} </h1> </span>
<h2> { GetLocalizedString(weapon.WeaponType, lang) } </h2>
<table>
<tbody>
<tr>
<td> { GetLocalizedString("Accuracy", lang) } </td>
<td> {weapon.Accuracy} </td>
</tr>
<tr>
<td> { GetLocalizedString("Concealability", lang) } </td>
<td> { GetLocalizedString(weapon.Concealability, lang) } </td>
</tr>
<tr>
<td> { GetLocalizedString("Avaliability", lang) } </td>
<td> { GetLocalizedString(weapon.Avaliability, lang) } </td>
</tr>
<tr>
<td> { GetLocalizedString("Damage/Ammunition", lang) } </td>
<td> {weapon.Damage}({weapon.Ammunition}) </td>
</tr>
<tr>
<td> { GetLocalizedString("Number Of Shots", lang) } </td>
<td> {weapon.NumberOfShots} </td>
</tr>
<tr>
<td> { GetLocalizedString("Rate Of Fire", lang) } </td>
<td> {weapon.RateOfFire} </td>
</tr>
<tr>
<td> { GetLocalizedString("Reliability", lang) } </td>
<td> { GetLocalizedString(weapon.Reliability, lang) } </td>
</tr>
</tbody>
</table>
</div>
);
}
async function getWeapon(id: string | undefined): Promise<RangedWeapon | null> {
if (id == undefined) return null;
try {
const {data, status} = await axios.get<RangedWeapon>(
`${RangedWeaponsURL}/${id}`,
{
headers: { Accept: "application/json" }
}
);
if (status != 200) return null;
return data;
} catch (err) {
console.log(`Failed to get ranged weapon: ${err}`);
return null;
}
}
export default RangedWeaponPage;
|