* wip: Add gridstack board * wip: Centralize board pages, Add board settings page * fix: remove cyclic dependency and rename widget-sort to kind * improve: Add header actions as parallel route * feat: add item select modal, add category edit modal, * feat: add edit item modal * feat: add remove item modal * wip: add category actions * feat: add saving of board, wip: add app widget * Merge branch 'main' into add-board * chore: update turbo dependencies * chore: update mantine dependencies * chore: fix typescript errors, lint and format * feat: add confirm modal to category removal, move items of removed category to above wrapper * feat: remove app widget to continue in another branch * feat: add loading spinner until board is initialized * fix: issue with cellheight of gridstack items * feat: add translations for board * fix: issue with translation for settings page * chore: address pull request feedback
34 lines
1.9 KiB
TypeScript
34 lines
1.9 KiB
TypeScript
import type { WidgetKind } from "@homarr/definitions";
|
|
import { useScopedI18n } from "@homarr/translation/client";
|
|
|
|
import type { WidgetOptionOfType, WidgetOptionType } from "../options";
|
|
|
|
export interface CommonWidgetInputProps<TKey extends WidgetOptionType> {
|
|
kind: WidgetKind;
|
|
property: string;
|
|
options: Omit<WidgetOptionOfType<TKey>, "defaultValue" | "type">;
|
|
}
|
|
|
|
type UseWidgetInputTranslationReturnType = (
|
|
key: "label" | "description",
|
|
) => string;
|
|
|
|
/**
|
|
* Short description why as and unknown convertions are used below:
|
|
* Typescript was not smart enought to work with the generic of the WidgetKind to only allow properties that are relying within that specified kind.
|
|
* This does not mean, that the function useWidgetInputTranslation can be called with invalid arguments without type errors and rather means that the above widget.<kind>.option.<property> string
|
|
* is not recognized as valid argument for the scoped i18n hook. Because the typesafety should remain outside the usage of those methods I (Meierschlumpf) decided to provide this fully typesafe useWidgetInputTranslation method.
|
|
*
|
|
* Some notes about it:
|
|
* - The label translation can be used for every input, especially considering that all options should have defined a label for themself. The description translation should only be used when withDescription
|
|
* is defined for the option. The method does sadly not reconize issues with those definitions. So it does not yell at you when you somewhere show the label without having it defined in the translations.
|
|
*/
|
|
export const useWidgetInputTranslation = (
|
|
kind: WidgetKind,
|
|
property: string,
|
|
): UseWidgetInputTranslationReturnType => {
|
|
return useScopedI18n(
|
|
`widget.${kind}.option.${property}` as never, // Because the type is complex and not recognized by typescript, we need to cast it to never to make it work.
|
|
) as unknown as UseWidgetInputTranslationReturnType;
|
|
};
|