Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UniSport_frontEnd
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swp-unisport
team-nodejs
UniSport_frontEnd
Commits
99ba4d56
Commit
99ba4d56
authored
Jul 12, 2021
by
philippkb
Committed by
lokmeinmatz
Jul 15, 2021
Browse files
Options
Downloads
Patches
Plain Diff
snack view is now updating the DB
parent
78e2a620
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/admin/snacks & co/SnacksView.tsx
+31
-3
31 additions, 3 deletions
src/components/admin/snacks & co/SnacksView.tsx
src/components/admin/synchronise/SynchroniseTableView.tsx
+56
-0
56 additions, 0 deletions
src/components/admin/synchronise/SynchroniseTableView.tsx
with
87 additions
and
3 deletions
src/components/admin/snacks & co/SnacksView.tsx
+
31
−
3
View file @
99ba4d56
...
@@ -10,6 +10,11 @@ import { AddDialog } from './AddDialog'
...
@@ -10,6 +10,11 @@ import { AddDialog } from './AddDialog'
import
ObjectID
from
'
bson-objectid
'
import
ObjectID
from
'
bson-objectid
'
import
{
ChangeDialog
}
from
'
./ChangeDialog
'
import
{
ChangeDialog
}
from
'
./ChangeDialog
'
import
{
IActivity
,
ISnack
}
from
'
../../../types/ApiTypes
'
import
{
IActivity
,
ISnack
}
from
'
../../../types/ApiTypes
'
import
{
updateSports
}
from
'
../../../redux/Slices/sportsSlice
'
import
{
updateCategoriesFromSport
}
from
'
../../../redux/Slices/categoriesSlice
'
import
{
updateSnacks
}
from
'
../../../redux/Slices/snacksSlice
'
import
{
useAppDispatch
}
from
'
../../../hooks
'
import
{
updateActivities
}
from
'
../../../redux/Slices/activitiesSlice
'
const
useStyles
=
makeStyles
((
theme
)
=>
({
const
useStyles
=
makeStyles
((
theme
)
=>
({
fab
:
{
fab
:
{
...
@@ -24,6 +29,7 @@ export const SnacksView: React.FC = () => {
...
@@ -24,6 +29,7 @@ export const SnacksView: React.FC = () => {
const
[
pages
,
setPages
]
=
useFetchSnacksAndActivities
()
const
[
pages
,
setPages
]
=
useFetchSnacksAndActivities
()
const
dialogConfirmState
=
useState
(
false
)
const
dialogConfirmState
=
useState
(
false
)
const
dialogAddState
=
useState
(
false
)
const
dialogAddState
=
useState
(
false
)
const
dispatch
=
useAppDispatch
()
const
actions
:
action
[]
=
[
const
actions
:
action
[]
=
[
{
{
handler
:
()
=>
dialogConfirmState
[
1
](
true
),
handler
:
()
=>
dialogConfirmState
[
1
](
true
),
...
@@ -37,7 +43,7 @@ export const SnacksView: React.FC = () => {
...
@@ -37,7 +43,7 @@ export const SnacksView: React.FC = () => {
}
}
]
]
function
saveToDB
()
{
async
function
saveToDB
()
{
let
snacks
:
ISnack
[]
=
[]
let
snacks
:
ISnack
[]
=
[]
let
activities
:
IActivity
[]
=
[]
let
activities
:
IActivity
[]
=
[]
pages
.
forEach
((
p
:
any
)
=>
{
pages
.
forEach
((
p
:
any
)
=>
{
...
@@ -49,8 +55,30 @@ export const SnacksView: React.FC = () => {
...
@@ -49,8 +55,30 @@ export const SnacksView: React.FC = () => {
activities
.
push
(
page
)
activities
.
push
(
page
)
}
}
})
})
console
.
log
(
snacks
)
const
resOne
=
await
fetch
(
'
/api/snacks
'
,
{
console
.
log
(
activities
)
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
(
snacks
)
}).
then
((
e
)
=>
{
console
.
log
(
e
)
if
(
e
.
ok
)
{
dispatch
(
updateSnacks
(
snacks
))
}
})
const
resTwo
=
await
fetch
(
'
/api/activities
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
(
activities
)
}).
then
((
e
)
=>
{
console
.
log
(
e
)
if
(
e
.
ok
)
{
dispatch
(
updateActivities
(
activities
))
}
})
}
}
function
addSnack
(
type
:
'
snack
'
|
'
activity
'
,
title
:
string
)
{
function
addSnack
(
type
:
'
snack
'
|
'
activity
'
,
title
:
string
)
{
...
...
This diff is collapsed.
Click to expand it.
src/components/admin/synchronise/SynchroniseTableView.tsx
+
56
−
0
View file @
99ba4d56
...
@@ -7,6 +7,7 @@ import { SynchroniseContainer } from './SynchroniseContainer'
...
@@ -7,6 +7,7 @@ import { SynchroniseContainer } from './SynchroniseContainer'
import
{
SyncApiData
,
SyncListEntry
}
from
'
./SynchroniseView
'
import
{
SyncApiData
,
SyncListEntry
}
from
'
./SynchroniseView
'
import
{
useRef
}
from
'
react
'
import
{
useRef
}
from
'
react
'
import
{
ConfirmDialog
}
from
'
../shared/Dialogs/ConfirmDialog
'
import
{
ConfirmDialog
}
from
'
../shared/Dialogs/ConfirmDialog
'
import
{
ISports
}
from
'
../../../types/ApiTypes
'
const
useStyles
=
makeStyles
((
theme
:
Theme
)
=>
const
useStyles
=
makeStyles
((
theme
:
Theme
)
=>
createStyles
({
createStyles
({
...
@@ -44,6 +45,45 @@ export const SynchroniseTableView: React.FC<SynchroniseTableViewProps> = ({
...
@@ -44,6 +45,45 @@ export const SynchroniseTableView: React.FC<SynchroniseTableViewProps> = ({
const
newSportsRef
=
useRef
(
newSports
)
const
newSportsRef
=
useRef
(
newSports
)
const
dialogConfirmState
=
useState
(
false
)
const
dialogConfirmState
=
useState
(
false
)
function
saveToDB
(
recR
:
React
.
MutableRefObject
<
(
SyncListEntry
&
{
lastActive
:
boolean
})[]
>
,
remR
:
React
.
MutableRefObject
<
SyncListEntry
[]
>
,
newR
:
React
.
MutableRefObject
<
SyncListEntry
[]
>
)
{
let
toRemove
:
{
name
:
string
;
url
:
string
}[]
=
[]
let
toAdd
:
{
name
:
string
;
url
:
string
}[]
=
[]
let
toActive
:
{
name
:
string
;
url
:
string
}[]
=
[]
let
toInactive
:
{
name
:
string
;
url
:
string
}[]
=
[]
remR
.
current
.
forEach
((
entry
)
=>
{
const
{
selected
,
...
rest
}
=
entry
if
(
!
selected
)
{
toRemove
.
push
(
rest
)
}
else
{
toInactive
.
push
(
rest
)
}
})
newR
.
current
.
forEach
((
entry
)
=>
{
if
(
entry
.
selected
)
{
const
{
selected
,
...
rest
}
=
entry
toAdd
.
push
(
rest
)
}
})
recR
.
current
.
forEach
((
entry
)
=>
{
const
{
selected
,
lastActive
,
...
rest
}
=
entry
if
(
selected
)
{
toActive
.
push
(
rest
)
}
else
{
toInactive
.
push
(
rest
)
}
})
console
.
log
(
toRemove
)
console
.
log
(
toAdd
)
console
.
log
(
toActive
)
console
.
log
(
toInactive
)
}
return
(
return
(
<
div
style
=
{
{
minHeight
:
'
100%
'
,
textAlign
:
'
center
'
}
}
>
<
div
style
=
{
{
minHeight
:
'
100%
'
,
textAlign
:
'
center
'
}
}
>
<
div
className
=
{
classes
.
div
}
>
<
div
className
=
{
classes
.
div
}
>
...
@@ -71,6 +111,22 @@ export const SynchroniseTableView: React.FC<SynchroniseTableViewProps> = ({
...
@@ -71,6 +111,22 @@ export const SynchroniseTableView: React.FC<SynchroniseTableViewProps> = ({
]
}
]
}
sportsRef
=
{
removedSportsRef
}
sportsRef
=
{
removedSportsRef
}
/>
/>
<
ConfirmDialog
handleCategorie
=
{
()
=>
saveToDB
(
recurringSportsRef
,
removedSportsRef
,
newSportsRef
)
}
state
=
{
dialogConfirmState
}
text
=
{
{
header
:
'
Speichern
'
,
body
:
'
Sollen die Änderungen gespeichert werden
'
,
confirm
:
'
Bestätigen
'
,
abort
:
'
Abbrechen
'
}
}
/>
</
div
>
</
div
>
<
Fab
<
Fab
...
...
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