Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

2.3 KB
Raw Blame
import { IconHeadphones, IconServerOff } from "@tabler/icons-react";

import { getWidgetIntegrationConfig } from "@homarr/definitions";

import { createWidgetDefinition, matchesWidgetRuntimeQuery } from "../definition";
import { optionsBuilder } from "../options";

const hideUnlessNavidrome = {
  shouldHide: (_: unknown, integrationKinds: string[]) =>
    !integrationKinds.includes("navidrome") && !integrationKinds.includes("mock"),
};

const hideUnlessAudiobookshelf = {
  shouldHide: (_: unknown, integrationKinds: string[]) => !integrationKinds.includes("audiobookshelf"),
};

export const { definition, componentLoader } = createWidgetDefinition("audioStats", {
  icon: IconHeadphones,
  supportsAdvancedFocus: true,
  queryKeys: [[["widget", "audioStats", "getStats"]], [["widget", "mediaServer", "getCurrentStreams"]]],
  queryMatcher: matchesWidgetRuntimeQuery,
  ...getWidgetIntegrationConfig("audioStats"),
  createOptions() {
    return optionsBuilder.from(
      (factory) => ({
        showArtists: factory.switch({ defaultValue: true, withDescription: true }),
        showAlbums: factory.switch({ defaultValue: true, withDescription: true }),
        showSongs: factory.switch({ defaultValue: true, withDescription: true }),
        showLibraryCount: factory.switch({ defaultValue: true, withDescription: true }),
        showAudiobooks: factory.switch({ defaultValue: true, withDescription: true }),
        showPodcasts: factory.switch({ defaultValue: true, withDescription: true }),
        showListeningTime: factory.switch({ defaultValue: true, withDescription: true }),
        showActiveSessions: factory.switch({ defaultValue: true, withDescription: true }),
        compactMode: factory.switch({ defaultValue: false, withDescription: true }),
      }),
      {
        showArtists: hideUnlessNavidrome,
        showAlbums: hideUnlessNavidrome,
        showSongs: hideUnlessNavidrome,
        showLibraryCount: hideUnlessAudiobookshelf,
        showAudiobooks: hideUnlessAudiobookshelf,
        showPodcasts: hideUnlessAudiobookshelf,
        showListeningTime: hideUnlessAudiobookshelf,
        showActiveSessions: hideUnlessAudiobookshelf,
      },
    );
  },
  errors: {
    INTERNAL_SERVER_ERROR: {
      icon: IconServerOff,
      message: (t) => t("widget.audioStats.error.internalServerError"),
    },
  },
}).withDynamicImport(() => import("./component"));