Skip to content

Commit

Permalink
Add a toast message on start for dependency updates (#2453)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyballentine authored Jan 12, 2024
1 parent 6f2d3aa commit 3e00f94
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/common/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
}
},
"dependencyManager": {
"manageDependencies": "Manage Dependencies"
"manageDependencies": "Manage Dependencies",
"updatesAvailable": "Updates Available",
"updatesAvailableDescription": "There are {{count}} updates available for your dependencies."
},
"error": {
"error": "Error",
Expand Down
34 changes: 31 additions & 3 deletions src/renderer/components/DependencyManagerButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DownloadIcon } from '@chakra-ui/icons';
import { IconButton, Tag, TagLabel, Tooltip, VStack } from '@chakra-ui/react';
import { memo } from 'react';
import { IconButton, Tag, TagLabel, Tooltip, VStack, useToast } from '@chakra-ui/react';
import { memo, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useContext } from 'use-context-selector';
import { DependencyContext } from '../contexts/DependencyContext';
Expand All @@ -10,6 +10,34 @@ export const DependencyManagerButton = memo(() => {

const { openDependencyManager, availableUpdates } = useContext(DependencyContext);

const toast = useToast();

const shownOnce = useRef(false);
useEffect(() => {
if (shownOnce.current) {
return;
}

if (availableUpdates > 0) {
toast({
title: t('dependencyManager.updatesAvailable', 'Updates Available'),
description: t(
'dependencyManager.updatesAvailableDescription',
'There are {{count}} packages with available dependency updates.',
{ count: availableUpdates }
),
status: 'info',
duration: 5000,
isClosable: true,
position: 'top-right',
onCloseComplete: () => {
shownOnce.current = false;
},
});
shownOnce.current = true;
}
}, [availableUpdates, t, toast]);

return (
<Tooltip
closeOnClick
Expand All @@ -26,7 +54,7 @@ export const DependencyManagerButton = memo(() => {
{availableUpdates > 0 ? (
<Tag
borderRadius="full"
colorScheme="red"
colorScheme="blue"
ml={-7}
mt={-1}
position="fixed"
Expand Down

0 comments on commit 3e00f94

Please sign in to comment.