Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cf2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
vojtech.pikal
cf2021
Commits
27379b1b
Commit
27379b1b
authored
4 years ago
by
xaralis
Browse files
Options
Downloads
Patches
Plain Diff
feat: handle 429 when adding new posts
parent
a250460b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/containers/AddPostForm.jsx
+16
-7
16 additions, 7 deletions
src/containers/AddPostForm.jsx
src/pages/Home.jsx
+18
-0
18 additions, 0 deletions
src/pages/Home.jsx
with
34 additions
and
7 deletions
src/containers/AddPostForm.jsx
+
16
−
7
View file @
27379b1b
...
...
@@ -21,10 +21,15 @@ const AddPostForm = ({ className }) => {
const
[
addingPost
,
addingPostError
]
=
useActionState
(
addPost
,
{
content
:
text
,
});
const
[
addingProposal
,
addingProposalError
]
=
useActionState
(
addP
ost
,
{
const
[
addingProposal
,
addingProposalError
]
=
useActionState
(
addP
roposal
,
{
content
:
text
,
});
const
apiError
=
addingPostError
||
addingProposalError
;
const
is429ApiError
=
apiError
&&
apiError
.
toString
().
indexOf
(
"
Unexpected status code 429
"
)
!==
-
1
;
const
onOutsideClick
=
useCallback
(()
=>
{
setExpanded
(
false
);
},
[
setExpanded
]);
...
...
@@ -113,14 +118,18 @@ const AddPostForm = ({ className }) => {
}
>
<
div
className
=
"space-y-4"
>
{
addingPostError
&&
(
<
ErrorMessage
>
Při přidávání příspěvku došlo k problému:
{
addingPostError
}
.
</
ErrorMessage
>
{
apiError
&&
is429ApiError
&&
(
<
div
className
=
"alert alert--warning"
>
<
i
className
=
"alert__icon ico--clock text-lg"
/>
<
span
>
<
strong
>
Zpomal!
</
strong
>
Další příspěvek můžeš přidat nejdříve
po 1 minutě od přidání posledního.
</
span
>
</
div
>
)
}
{
a
ddingProposal
Error
&&
(
{
a
piError
&&
!
is429Api
Error
&&
(
<
ErrorMessage
>
Při přidávání příspěvku došlo k problému:
{
a
ddingProposal
Error
}
.
Při přidávání příspěvku došlo k problému:
{
a
pi
Error
}
.
</
ErrorMessage
>
)
}
...
...
This diff is collapsed.
Click to expand it.
src/pages/Home.jsx
+
18
−
0
View file @
27379b1b
...
...
@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useState } from "react";
import
{
Helmet
}
from
"
react-helmet-async
"
;
import
Joyride
,
{
EVENTS
}
from
"
react-joyride
"
;
import
ReactPlayer
from
"
react-player/lazy
"
;
import
{
useKeycloak
}
from
"
@react-keycloak/web
"
;
import
useWindowSize
from
"
@rooks/use-window-size
"
;
import
{
...
...
@@ -66,6 +67,11 @@ const Home = () => {
onEndProgramPointConfirm
,
onEndProgramPointCancel
,
]
=
useActionConfirm
(
endProgramPoint
,
programEntry
);
const
{
keycloak
}
=
useKeycloak
();
const
login
=
useCallback
(()
=>
{
keycloak
.
login
();
},
[
keycloak
]);
useEffect
(()
=>
{
if
(
isLg
&&
!
localStorage
.
getItem
(
tourLSKey
))
{
...
...
@@ -303,6 +309,18 @@ const Home = () => {
Rozprava je uzavřena - příspěvky teď nelze přidávat.
</
p
>
)
}
{
programEntry
.
discussionOpened
&&
!
isAuthenticated
&&
(
<
p
className
=
"alert alert--light items-center mb-4"
>
<
i
className
=
"alert__icon ico--info text-lg"
/>
<
span
>
Pokud chceš přidat nový příspěvek,
{
"
"
}
<
button
onClick
=
{
login
}
className
=
"underline cursor-pointer"
>
přihlaš se pomocí Pirátské identity
</
button
>
.
</
span
>
</
p
>
)
}
{
programEntry
.
discussionOpened
&&
isAuthenticated
&&
user
.
isBanned
&&
(
<
p
className
=
"alert alert--error items-center mb-4"
>
<
i
className
=
"alert__icon ico--warning text-lg"
/>
...
...
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