mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-27 17:17:40 +03:00
single condition check for fetching and disabling button
This commit is contained in:
parent
72b591efb1
commit
fe5dd1e67d
@ -165,13 +165,27 @@ export default function NotificationView({
|
|||||||
const watchAllEnabled = form.watch("allEnabled");
|
const watchAllEnabled = form.watch("allEnabled");
|
||||||
const watchCameras = useMemo(() => form.watch("cameras") || [], [form]);
|
const watchCameras = useMemo(() => form.watch("cameras") || [], [form]);
|
||||||
|
|
||||||
const { data: publicKey } = useSWR(
|
const anyCameraNotificationsEnabled = useMemo(
|
||||||
|
() =>
|
||||||
config &&
|
config &&
|
||||||
(config.notifications?.enabled ||
|
Object.values(config.cameras).some(
|
||||||
watchAllEnabled ||
|
(c) =>
|
||||||
(Array.isArray(watchCameras) && watchCameras.length > 0))
|
c.enabled_in_config &&
|
||||||
? "notifications/pubkey"
|
c.notifications &&
|
||||||
: null,
|
c.notifications.enabled_in_config,
|
||||||
|
),
|
||||||
|
[config],
|
||||||
|
);
|
||||||
|
|
||||||
|
const shouldFetchPubKey = Boolean(
|
||||||
|
config &&
|
||||||
|
(config.notifications?.enabled || anyCameraNotificationsEnabled) &&
|
||||||
|
(watchAllEnabled ||
|
||||||
|
(Array.isArray(watchCameras) && watchCameras.length > 0)),
|
||||||
|
);
|
||||||
|
|
||||||
|
const { data: publicKey } = useSWR(
|
||||||
|
shouldFetchPubKey ? "notifications/pubkey" : null,
|
||||||
{ revalidateOnFocus: false },
|
{ revalidateOnFocus: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -525,13 +539,7 @@ export default function NotificationView({
|
|||||||
</Heading>
|
</Heading>
|
||||||
<Button
|
<Button
|
||||||
aria-label={t("notification.registerDevice")}
|
aria-label={t("notification.registerDevice")}
|
||||||
disabled={
|
disabled={!shouldFetchPubKey || publicKey == undefined}
|
||||||
(!config?.notifications.enabled &&
|
|
||||||
notificationCameras.length === 0 &&
|
|
||||||
!form.watch("allEnabled") &&
|
|
||||||
form.watch("cameras").length === 0) ||
|
|
||||||
publicKey == undefined
|
|
||||||
}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (registration == null) {
|
if (registration == null) {
|
||||||
Notification.requestPermission().then((permission) => {
|
Notification.requestPermission().then((permission) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user