feat!: release v2 (#6545)
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com> Co-authored-by: arturict <arturict@users.noreply.github.com> Co-authored-by: Thomas <thomas@ajnart.fr> Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com> Co-authored-by: Danura30082 <danura30082+github@gmail.com> Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com> Co-authored-by: ajnart <thomas@ajnart.fr> Co-authored-by: ajnart <thomas@ajnart.dev> Co-authored-by: chenjun <chenjun@foxmail.com> Co-authored-by: Wikibear <wikibear@users.noreply.github.com> Co-authored-by: Bergasha <bergasha@gmail.com> Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com> Co-authored-by: Lucas Araujo <lucas.lra@gmail.com> Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com> Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social> Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com> Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com> Co-authored-by: thrawnx <tight.bulb9384@fastmail.com> Co-authored-by: Chris <58918656+nordada@users.noreply.github.com> Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com> Co-authored-by: Yanis <naamaneyanis@gmail.com> Co-authored-by: Wikibear <me@sej.de> Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386
-139176
No files matched your search
@@ -16,46 +16,56 @@ import type Player from "video.js/dist/types/player";
|
||||
|
||||
import { createDocumentationLink } from "@homarr/definitions";
|
||||
|
||||
export default function VideoWidget({ options }: WidgetComponentProps<"video">) {
|
||||
export default function VideoWidget({ options, isEditMode }: WidgetComponentProps<"video">) {
|
||||
if (options.feedUrl.trim() === "") {
|
||||
return <NoUrl />;
|
||||
}
|
||||
|
||||
if (options.feedUrl.trim().startsWith("https://www.youtube.com/watch")) {
|
||||
if (isYouTubeUrl(options.feedUrl)) {
|
||||
return <ForYoutubeUseIframe />;
|
||||
}
|
||||
|
||||
return <Feed options={options} />;
|
||||
return <Feed options={options} isEditMode={isEditMode} />;
|
||||
}
|
||||
|
||||
export const isYouTubeUrl = (value: string): boolean => {
|
||||
try {
|
||||
const url = new URL(value);
|
||||
return url.hostname === "youtu.be" || url.hostname === "youtube.com" || url.hostname.endsWith(".youtube.com");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const NoUrl = () => {
|
||||
const t = useI18n();
|
||||
const t = useI18n("widget.video");
|
||||
|
||||
return (
|
||||
<Center h="100%">
|
||||
<Stack align="center">
|
||||
<IconDeviceCctvOff />
|
||||
<Title order={4}>{t("widget.video.error.noUrl")}</Title>
|
||||
<Title order={4}>{t("error.noUrl")}</Title>
|
||||
</Stack>
|
||||
</Center>
|
||||
);
|
||||
};
|
||||
|
||||
const ForYoutubeUseIframe = () => {
|
||||
const t = useI18n();
|
||||
const t = useI18n("widget.video");
|
||||
const tCommon = useI18n("common");
|
||||
|
||||
return (
|
||||
<Center h="100%">
|
||||
<Stack align="center" gap="xs">
|
||||
<IconBrandYoutube />
|
||||
<Title order={4}>{t("widget.video.error.forYoutubeUseIframe")}</Title>
|
||||
<Anchor href={createDocumentationLink("/docs/widgets/iframe")}>{t("common.action.checkoutDocs")}</Anchor>
|
||||
<Title order={4}>{t("error.forYoutubeUseIframe")}</Title>
|
||||
<Anchor href={createDocumentationLink("/docs/widgets/iframe")}>{tCommon("action.checkoutDocs")}</Anchor>
|
||||
</Stack>
|
||||
</Center>
|
||||
);
|
||||
};
|
||||
|
||||
const Feed = ({ options }: Pick<WidgetComponentProps<"video">, "options">) => {
|
||||
const Feed = ({ options, isEditMode }: Pick<WidgetComponentProps<"video">, "options"> & { isEditMode: boolean }) => {
|
||||
const videoRef = useRef<HTMLDivElement>(null);
|
||||
const playerRef = useRef<Player>(null);
|
||||
|
||||
@@ -98,8 +108,8 @@ const Feed = ({ options }: Pick<WidgetComponentProps<"video">, "options">) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (!playerRef.current) return;
|
||||
playerRef.current.controls(options.hasControls);
|
||||
}, [options.hasControls]);
|
||||
playerRef.current.controls(!isEditMode && options.hasControls);
|
||||
}, [isEditMode, options.hasControls]);
|
||||
|
||||
useEffect(() => {
|
||||
const player = playerRef.current;
|
||||
@@ -113,7 +123,7 @@ const Feed = ({ options }: Pick<WidgetComponentProps<"video">, "options">) => {
|
||||
}, [playerRef]);
|
||||
|
||||
return (
|
||||
<Group justify="center" w="100%" h="100%" pos="relative">
|
||||
<Group justify="center" w="100%" h="100%" pos="relative" style={{ pointerEvents: isEditMode ? "none" : undefined }}>
|
||||
<Box w="100%" h="100%" ref={videoRef} />
|
||||
</Group>
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("video", {
|
||||
supportsAdvancedFocus: false,
|
||||
icon: IconDeviceCctv,
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
|
||||
Reference in new issue
Block a user