Skip to content

Commit

Permalink
Merge pull request #194 from TouK/NU-1087/auto-update-subscription-st…
Browse files Browse the repository at this point in the history
…atus

NU-1087 auto update subscription status
  • Loading branch information
bohdanprog authored Oct 3, 2023
2 parents bcec68e + 2cc8619 commit fb808e0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/subscriptionListElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ import { LinePlaceholder } from "./linePlaceholder";

export const SubscriptionListElement = observer(({ subscription }: { subscription: Subscription }) => {
const navigate = useNavigate();
const state = subscription.state;
const noExist = state === undefined;
const notActive = state !== "ACTIVE" && state !== undefined;
const active = state === "ACTIVE";

useEffect(() => {
subscription.fetchTask();
}, [subscription]);
let interval;
if (noExist) {
subscription.fetchTask();
} else if (notActive) {
interval = setInterval(() => subscription.fetchTask(), 10000);
} else if (active) {
clearInterval(interval);
}
return () => clearInterval(interval);
}, [subscription, noExist, notActive, active]);

return (
<ListItemButton onClick={() => navigate(subscription.name)}>
Expand Down

0 comments on commit fb808e0

Please sign in to comment.