-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Event project and asset notification
- Loading branch information
1 parent
1603d70
commit 1d875e4
Showing
14 changed files
with
183 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/projects/components/project-page/parts/project-page-body/parts/refresher/Refresher.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import SSEContext from "@/core/sse/SSEContext"; | ||
import { Anchor } from "@mantine/core"; | ||
import { useId } from "@mantine/hooks"; | ||
import { notifications } from "@mantine/notifications"; | ||
import { useContext, useEffect, useState } from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
type RefresherProps = { | ||
projectUUID: string; | ||
} | ||
|
||
export function Refresher({ projectUUID }: RefresherProps) { | ||
const subscriberId = useId(); | ||
const { connected, subscribe, unsubscribe } = useContext(SSEContext) | ||
const [assetUpdate, setAssetUpdate] = useState({} as any) | ||
const [error, setError] = useState<Error | null>(null); | ||
useEffect(() => { | ||
if (!connected) return; | ||
setAssetUpdate({}) | ||
const subscription = { | ||
subscriberId, | ||
provider: `system/events`, | ||
} | ||
subscribe({ | ||
...subscription, | ||
event: `system.state.asset.event`, | ||
callback: setAssetUpdate | ||
}).catch(setError); | ||
return () => { | ||
unsubscribe(subscriberId) | ||
} | ||
}, [connected]) | ||
|
||
useEffect(() => { | ||
console.log(assetUpdate) | ||
if (!assetUpdate.state) return; | ||
if (projectUUID == assetUpdate.state.projectUUID) { | ||
notifications.show({ | ||
title: `Assets have changed`, | ||
message: <Anchor component={Link} reloadDocument to={`/projects/${projectUUID}`}>Refresh</Anchor>, | ||
}) | ||
} | ||
}, [assetUpdate]) | ||
return (<></>) | ||
} |
40 changes: 40 additions & 0 deletions
40
src/projects/components/project-page/parts/refresher/Refresher.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import SSEContext from "@/core/sse/SSEContext"; | ||
import { useId } from "@mantine/hooks"; | ||
import { useContext, useEffect, useState } from "react"; | ||
|
||
type RefresherProps = { | ||
projectUUID: string; | ||
refresh: () => void; | ||
} | ||
|
||
export function Refresher({ projectUUID, refresh }: RefresherProps) { | ||
const subscriberId = useId(); | ||
const { connected, subscribe, unsubscribe } = useContext(SSEContext) | ||
const [projectUpdate, setProjectUpdate] = useState({} as any) | ||
const [error, setError] = useState<Error | null>(null); | ||
useEffect(() => { | ||
if (!connected) return; | ||
setProjectUpdate({}) | ||
const subscription = { | ||
subscriberId, | ||
provider: `system/events`, | ||
} | ||
subscribe({ | ||
...subscription, | ||
event: `system.state.project.event`, | ||
callback: setProjectUpdate | ||
}).catch(setError); | ||
return () => { | ||
unsubscribe(subscriberId) | ||
} | ||
}, [connected]) | ||
|
||
useEffect(() => { | ||
console.log(projectUpdate) | ||
if (!projectUpdate.state) return; | ||
if (projectUpdate.state.projectUUID == projectUUID && projectUpdate.state.type == "update") { | ||
refresh(); | ||
} | ||
}, [projectUpdate]) | ||
return (<></>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/system/components/discovery-notifications/DiscoveryNotifications.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import SSEContext from "@/core/sse/SSEContext"; | ||
import { rem } from "@mantine/core"; | ||
import { useId } from "@mantine/hooks"; | ||
import { notifications } from "@mantine/notifications"; | ||
import { IconCheck } from "@tabler/icons-react"; | ||
import { useContext, useEffect, useState } from "react"; | ||
|
||
export function DiscoveryNotifications() { | ||
const subscriberId = useId(); | ||
const { connected, subscribe, unsubscribe } = useContext(SSEContext) | ||
const [id, setId] = useState<string | null>(null); | ||
const [message, setMessage] = useState({} as any) | ||
const [error, setError] = useState<Error | null>(null); | ||
useEffect(() => { | ||
if (!connected) return; | ||
setMessage("") | ||
const subscription = { | ||
subscriberId, | ||
provider: `system/events`, | ||
} | ||
subscribe({ | ||
...subscription, | ||
event: `system.state.discovery.scan`, | ||
callback: setMessage | ||
}).catch(setError); | ||
return () => { | ||
unsubscribe(subscriberId) | ||
} | ||
}, [connected]) | ||
|
||
useEffect(() => { | ||
console.log(message) | ||
if (!message.state) return; | ||
if (message.state.state == "started") { | ||
setId(notifications.show({ | ||
loading: true, | ||
title: "New Scan started", | ||
message: "Let's find new projects!", | ||
autoClose: false | ||
})) | ||
} else if (id) { | ||
notifications.update({ | ||
id, | ||
color: 'teal', | ||
title: 'Scan finished!', | ||
message: '', | ||
icon: <IconCheck style={{ width: rem(18), height: rem(18) }} />, | ||
loading: false, | ||
autoClose: 2000, | ||
}); | ||
} | ||
}, [message]) | ||
return (<></>) | ||
} |