Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simple-fullstack
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aron Nikku
simple-fullstack
Commits
312ebd05
Commit
312ebd05
authored
4 months ago
by
Aron Nikku
Browse files
Options
Downloads
Patches
Plain Diff
Fixed form working with backend
parent
bb8d577e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
frontend/src/api.ts
+6
-1
6 additions, 1 deletion
frontend/src/api.ts
frontend/src/pages/FormPage.tsx
+3
-0
3 additions, 0 deletions
frontend/src/pages/FormPage.tsx
frontend/src/types.ts
+11
-6
11 additions, 6 deletions
frontend/src/types.ts
with
21 additions
and
7 deletions
.gitignore
+
1
−
0
View file @
312ebd05
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
*/__pycache__/
*/__pycache__/
*.pyc
*.pyc
*.db
# Logs
# Logs
logs
logs
...
...
This diff is collapsed.
Click to expand it.
frontend/src/api.ts
+
6
−
1
View file @
312ebd05
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
import
{
Character
}
from
'
./types
'
;
import
{
Character
,
CharacterCreate
}
from
'
./types
'
;
const
API_BASE
=
'
http://localhost:8000
'
;
const
API_BASE
=
'
http://localhost:8000
'
;
...
@@ -12,3 +12,8 @@ export async function damageCharacter(id: number): Promise<Character> {
...
@@ -12,3 +12,8 @@ export async function damageCharacter(id: number): Promise<Character> {
const
response
=
await
axios
.
post
(
`
${
API_BASE
}
/damage/
${
id
}
`
);
const
response
=
await
axios
.
post
(
`
${
API_BASE
}
/damage/
${
id
}
`
);
return
response
.
data
;
return
response
.
data
;
}
}
export
async
function
addCharacter
(
data
:
CharacterCreate
):
Promise
<
Character
>
{
const
response
=
await
axios
.
post
(
`
${
API_BASE
}
/characters`
,
data
=
data
);
return
response
.
data
;
}
This diff is collapsed.
Click to expand it.
frontend/src/pages/FormPage.tsx
+
3
−
0
View file @
312ebd05
...
@@ -2,6 +2,7 @@ import { Container, Title } from '@mantine/core';
...
@@ -2,6 +2,7 @@ import { Container, Title } from '@mantine/core';
import
{
useForm
}
from
'
@mantine/form
'
;
import
{
useForm
}
from
'
@mantine/form
'
;
import
{
TextInput
,
NumberInput
,
Button
,
Box
}
from
'
@mantine/core
'
;
import
{
TextInput
,
NumberInput
,
Button
,
Box
}
from
'
@mantine/core
'
;
import
{
addCharacter
}
from
'
../api
'
;
function
CharacterForm
()
{
function
CharacterForm
()
{
const
form
=
useForm
({
const
form
=
useForm
({
...
@@ -19,6 +20,8 @@ function CharacterForm() {
...
@@ -19,6 +20,8 @@ function CharacterForm() {
const
handleSubmit
=
(
values
:
typeof
form
.
values
)
=>
{
const
handleSubmit
=
(
values
:
typeof
form
.
values
)
=>
{
console
.
log
(
'
Character data:
'
,
values
);
console
.
log
(
'
Character data:
'
,
values
);
// you could pass this data to a parent or send to API, etc.
// you could pass this data to a parent or send to API, etc.
addCharacter
({
name
:
values
.
name
,
max_hp
:
values
.
hp
})
};
};
return
(
return
(
...
...
This diff is collapsed.
Click to expand it.
frontend/src/types.ts
+
11
−
6
View file @
312ebd05
export
interface
Character
{
export
interface
Character
{
id
:
number
;
id
:
number
;
name
:
string
;
name
:
string
;
max_hp
:
number
;
max_hp
:
number
;
current_hp
:
number
;
current_hp
:
number
;
is_dead
:
boolean
;
is_dead
:
boolean
;
}
}
export
interface
CharacterCreate
{
name
:
string
;
max_hp
:
number
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment