| 1 | import { useWebviewListener } from "../../hooks/useWebviewListener"; |
| 2 | import { useAppDispatch } from "../../redux/hooks"; |
| 3 | import { setIsExploreDialogOpen } from "../../redux/slices/uiSlice"; |
| 4 | import { |
| 5 | getLocalStorage, |
| 6 | LocalStorageKey, |
| 7 | setLocalStorage, |
| 8 | } from "../../util/localStorage"; |
| 9 | |
| 10 | const useTutorialListener = (onTutorialClosed: () => void) => { |
| 11 | useWebviewListener("didCloseFiles", async (data) => { |
| 12 | const uris = data?.uris ?? []; |
| 13 | |
| 14 | const isTutorial = uris.some((uri) => { |
| 15 | const lowercaseUri = uri.toLowerCase(); |
| 16 | return ( |
| 17 | lowercaseUri.endsWith("continue_tutorial.py") || |
| 18 | lowercaseUri.endsWith("continue_tutorial.java") || |
| 19 | lowercaseUri.endsWith("continue_tutorial.ts") |
| 20 | ); |
| 21 | }); |
| 22 | |
| 23 | if (isTutorial) { |
| 24 | onTutorialClosed(); |
| 25 | } |
| 26 | }); |
| 27 | }; |
| 28 | |
| 29 | export const ExploreDialogWatcher = () => { |
| 30 | const dispatch = useAppDispatch(); |
| 31 | |
| 32 | useTutorialListener(() => { |
| 33 | setLocalStorage(LocalStorageKey.IsExploreDialogOpen, true); |
| 34 | |
| 35 | if (!getLocalStorage(LocalStorageKey.HasDismissedExploreDialog)) { |
| 36 | dispatch(setIsExploreDialogOpen(true)); |
| 37 | } |
| 38 | }); |
| 39 | return null; |
| 40 | }; |