Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Infoscreen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evy Storozhenko
Infoscreen
Commits
d978d3d6
Commit
d978d3d6
authored
1 year ago
by
Niklas Schrötler
Browse files
Options
Downloads
Patches
Plain Diff
MensaplanPanel: Added handling for failing requests
parent
e36e901e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/panels/Mensaplan/MensaplanPanel.tsx
+83
-76
83 additions, 76 deletions
src/panels/Mensaplan/MensaplanPanel.tsx
with
83 additions
and
76 deletions
src/panels/Mensaplan/MensaplanPanel.tsx
+
83
−
76
View file @
d978d3d6
...
@@ -29,85 +29,92 @@ const MensaplanPanel = (props: {definition: MensaPanelDefinition}) => {
...
@@ -29,85 +29,92 @@ const MensaplanPanel = (props: {definition: MensaPanelDefinition}) => {
useEffect
(()
=>
{
useEffect
(()
=>
{
const
update
=
async
()
=>
{
const
update
=
async
()
=>
{
// Determine day to fetch for
try
{
const
now
=
new
Date
();
// Determine day to fetch for
let
fetchFor
:
string
;
const
now
=
new
Date
();
let
fetchFor
:
string
;
if
(
now
.
getHours
()
>
props
.
definition
.
closingTime
.
hours
||
(
if
(
now
.
getHours
()
===
props
.
definition
.
closingTime
.
hours
&&
now
.
getHours
()
>
props
.
definition
.
closingTime
.
hours
||
(
now
.
getMinutes
()
>
props
.
definition
.
closingTime
.
minutes
now
.
getHours
()
===
props
.
definition
.
closingTime
.
hours
&&
)
now
.
getMinutes
()
>
props
.
definition
.
closingTime
.
minutes
)
{
)
// After closing, fetch for next day
)
{
setRelativeDay
(
"
morgen
"
);
// After closing, fetch for next day
const
tomorrow
=
new
Date
(
now
.
setTime
(
now
.
getTime
()
+
24
*
60
*
60
*
1000
));
setRelativeDay
(
"
morgen
"
);
fetchFor
=
toYYYYMMDD
(
tomorrow
);
const
tomorrow
=
new
Date
(
now
.
setTime
(
now
.
getTime
()
+
24
*
60
*
60
*
1000
));
}
else
{
fetchFor
=
toYYYYMMDD
(
tomorrow
);
// otherwise, fetch for today
}
else
{
setRelativeDay
(
"
heute
"
);
// otherwise, fetch for today
fetchFor
=
toYYYYMMDD
(
now
);
setRelativeDay
(
"
heute
"
);
fetchFor
=
toYYYYMMDD
(
now
);
}
// Request the API
const
request
=
await
fetch
(
`https://infoscreen.oh14.de/canteen-menu/v3/canteens/
${
props
.
definition
.
canteenId
}
/
${
fetchFor
}
`
);
if
(
!
(
request
.
status
===
200
))
{
menus
.
current
=
[];
specials
.
current
=
[];
return
;
}
const
data
=
await
request
.
json
()
as
CanteenAPIResponse
;
console
.
log
(
data
);
const
old_menus_count
=
menus
.
current
.
length
;
const
old_specials_count
=
menus
.
current
.
length
;
// ToDo: This needs to be cleaned up!
menus
.
current
=
data
.
filter
(
d
=>
d
.
counter
!==
"
Beilagen
"
)
.
filter
(
d
=>
d
.
counter
!==
"
Aktionsteller
"
)
.
sort
((
a
,
b
)
=>
{
return
a
.
position
-
b
.
position
})
.
map
(
d
=>
({
name
:
(
d
.
title
.
de
.
split
(
"
|
"
)
.
at
(
0
)
??
"
Name nicht bekannt
"
)
.
replace
(
"
nach Wahl
"
,
""
),
details
:
d
.
title
.
de
.
split
(
"
|
"
)
.
slice
(
1
,
-
1
)
.
join
(
"
,
"
)
.
replace
(
"
nach Wahl
"
,
""
),
typeIcons
:
d
.
type
.
map
(
typeToIcon
).
filter
(
i
=>
i
!==
null
)
as
unknown
as
React
.
FC
<
any
>
[]
}))
specials
.
current
=
data
.
filter
(
d
=>
d
.
counter
===
"
Aktionsteller
"
)
.
sort
((
a
,
b
)
=>
{
return
a
.
position
-
b
.
position
})
.
map
(
d
=>
({
name
:
(
d
.
title
.
de
.
split
(
"
|
"
)
.
at
(
0
)
??
"
Name nicht bekannt
"
)
.
replace
(
"
nach Wahl
"
,
""
),
details
:
d
.
title
.
de
.
split
(
"
|
"
)
.
slice
(
1
,
-
1
)
.
join
(
"
,
"
)
.
replace
(
"
nach Wahl
"
,
""
),
typeIcons
:
d
.
type
.
map
(
typeToIcon
).
filter
(
i
=>
i
!==
null
)
as
unknown
as
React
.
FC
<
any
>
[]
}))
// If the count of menus and specials changed, reset the cycler
if
(
menus
.
current
.
length
!==
old_menus_count
||
specials
.
current
.
length
!==
old_specials_count
)
{
setDishes
(
menus
.
current
);
cycle
.
current
=
0
;
setGroupName
(
"
Menüs
"
)
}
}
}
catch
(
e
)
{
// Request the API
console
.
warn
(
"
MensaPlan not showing data because
"
,
e
);
const
request
=
await
fetch
(
`https://infoscreen.oh14.de/canteen-menu/v3/canteens/
${
props
.
definition
.
canteenId
}
/
${
fetchFor
}
`
);
if
(
!
(
request
.
status
===
200
))
{
menus
.
current
=
[];
menus
.
current
=
[];
specials
.
current
=
[];
specials
.
current
=
[];
return
;
}
const
data
=
await
request
.
json
()
as
CanteenAPIResponse
;
console
.
log
(
data
);
const
old_menus_count
=
menus
.
current
.
length
;
const
old_specials_count
=
menus
.
current
.
length
;
// ToDo: This needs to be cleaned up!
menus
.
current
=
data
.
filter
(
d
=>
d
.
counter
!==
"
Beilagen
"
)
.
filter
(
d
=>
d
.
counter
!==
"
Aktionsteller
"
)
.
sort
((
a
,
b
)
=>
{
return
a
.
position
-
b
.
position
})
.
map
(
d
=>
({
name
:
(
d
.
title
.
de
.
split
(
"
|
"
)
.
at
(
0
)
??
"
Name nicht bekannt
"
)
.
replace
(
"
nach Wahl
"
,
""
),
details
:
d
.
title
.
de
.
split
(
"
|
"
)
.
slice
(
1
,
-
1
)
.
join
(
"
,
"
)
.
replace
(
"
nach Wahl
"
,
""
),
typeIcons
:
d
.
type
.
map
(
typeToIcon
).
filter
(
i
=>
i
!==
null
)
as
unknown
as
React
.
FC
<
any
>
[]
}))
specials
.
current
=
data
.
filter
(
d
=>
d
.
counter
===
"
Aktionsteller
"
)
.
sort
((
a
,
b
)
=>
{
return
a
.
position
-
b
.
position
})
.
map
(
d
=>
({
name
:
(
d
.
title
.
de
.
split
(
"
|
"
)
.
at
(
0
)
??
"
Name nicht bekannt
"
)
.
replace
(
"
nach Wahl
"
,
""
),
details
:
d
.
title
.
de
.
split
(
"
|
"
)
.
slice
(
1
,
-
1
)
.
join
(
"
,
"
)
.
replace
(
"
nach Wahl
"
,
""
),
typeIcons
:
d
.
type
.
map
(
typeToIcon
).
filter
(
i
=>
i
!==
null
)
as
unknown
as
React
.
FC
<
any
>
[]
}))
// If the count of menus and specials changed, reset the cycler
if
(
menus
.
current
.
length
!==
old_menus_count
||
specials
.
current
.
length
!==
old_specials_count
)
{
setDishes
(
menus
.
current
);
cycle
.
current
=
0
;
setGroupName
(
"
Menüs
"
)
}
}
}
}
...
...
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