-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(settings): add simple-ping settings (#2118)
- Loading branch information
1 parent
c04c42d
commit dff6cb9
Showing
88 changed files
with
4,489 additions
and
582 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 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
118 changes: 0 additions & 118 deletions
118
apps/nextjs/src/app/[locale]/boards/(content)/_context.tsx
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
67 changes: 67 additions & 0 deletions
67
apps/nextjs/src/app/[locale]/boards/(content)/_ready-context.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,67 @@ | ||
"use client"; | ||
|
||
import type { PropsWithChildren } from "react"; | ||
import { createContext, useCallback, useContext, useEffect, useState } from "react"; | ||
import { usePathname } from "next/navigation"; | ||
|
||
import { clientApi } from "@homarr/api/client"; | ||
import { useRequiredBoard } from "@homarr/boards/context"; | ||
|
||
const BoardReadyContext = createContext<{ | ||
isReady: boolean; | ||
markAsReady: (id: string) => void; | ||
} | null>(null); | ||
|
||
export const BoardReadyProvider = ({ children }: PropsWithChildren) => { | ||
const pathname = usePathname(); | ||
const utils = clientApi.useUtils(); | ||
const board = useRequiredBoard(); | ||
const [readySections, setReadySections] = useState<string[]>([]); | ||
|
||
// Reset sections required for ready state | ||
useEffect(() => { | ||
return () => { | ||
setReadySections([]); | ||
}; | ||
}, [pathname, utils]); | ||
|
||
useEffect(() => { | ||
setReadySections((previous) => previous.filter((id) => board.sections.some((section) => section.id === id))); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [board.sections.length, setReadySections]); | ||
|
||
const markAsReady = useCallback((id: string) => { | ||
setReadySections((previous) => (previous.includes(id) ? previous : [...previous, id])); | ||
}, []); | ||
|
||
return ( | ||
<BoardReadyContext.Provider | ||
value={{ | ||
isReady: board.sections.length === readySections.length, | ||
markAsReady, | ||
}} | ||
> | ||
{children} | ||
</BoardReadyContext.Provider> | ||
); | ||
}; | ||
|
||
export const useMarkSectionAsReady = () => { | ||
const context = useContext(BoardReadyContext); | ||
|
||
if (!context) { | ||
throw new Error("BoardReadyProvider is required"); | ||
} | ||
|
||
return context.markAsReady; | ||
}; | ||
|
||
export const useIsBoardReady = () => { | ||
const context = useContext(BoardReadyContext); | ||
|
||
if (!context) { | ||
throw new Error("BoardReadyProvider is required"); | ||
} | ||
|
||
return context.isReady; | ||
}; |
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
48 changes: 48 additions & 0 deletions
48
apps/nextjs/src/app/[locale]/boards/[name]/settings/_behavior.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,48 @@ | ||
"use client"; | ||
|
||
import { Button, Group, Stack, Switch } from "@mantine/core"; | ||
|
||
import { useForm } from "@homarr/form"; | ||
import { useI18n } from "@homarr/translation/client"; | ||
|
||
import type { Board } from "../../_types"; | ||
import { useSavePartialSettingsMutation } from "./_shared"; | ||
|
||
interface Props { | ||
board: Board; | ||
} | ||
|
||
export const BehaviorSettingsContent = ({ board }: Props) => { | ||
const t = useI18n(); | ||
const { mutate: savePartialSettings, isPending } = useSavePartialSettingsMutation(board); | ||
const form = useForm({ | ||
initialValues: { | ||
disableStatus: board.disableStatus, | ||
}, | ||
}); | ||
|
||
return ( | ||
<form | ||
onSubmit={form.onSubmit((values) => { | ||
savePartialSettings({ | ||
id: board.id, | ||
...values, | ||
}); | ||
})} | ||
> | ||
<Stack> | ||
<Switch | ||
label={t("board.field.disableStatus.label")} | ||
description={t("board.field.disableStatus.description")} | ||
{...form.getInputProps("disableStatus", { type: "checkbox" })} | ||
/> | ||
|
||
<Group justify="end"> | ||
<Button type="submit" loading={isPending} color="teal"> | ||
{t("common.action.saveChanges")} | ||
</Button> | ||
</Group> | ||
</Stack> | ||
</form> | ||
); | ||
}; |
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
Oops, something went wrong.