-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalise Media Library selection dialog
Allows other components and custom components to prompt for users to select an item from the library
- Loading branch information
1 parent
d16daf0
commit 77a5db3
Showing
8 changed files
with
75 additions
and
32 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { showDialog } from "../dialogs/make-dialog-manager"; | ||
import type { Constructor } from "../types"; | ||
import type { HassBaseEl } from "./hass-base-mixin"; | ||
import type { MediaPlayerBrowseDialogParams } from "../dialogs/media-browse/show-media-browser-dialog"; | ||
import type { PropertyValues } from "lit-element"; | ||
import type { HASSDomEvent } from "../common/dom/fire_event"; | ||
|
||
declare global { | ||
// for fire event | ||
interface HASSDomEvents { | ||
"hass-media-browse": MediaPlayerBrowseDialogParams; | ||
} | ||
} | ||
|
||
let mediaBrowseImportPromise; | ||
const importMediaBrowse = () => { | ||
if (!mediaBrowseImportPromise) { | ||
mediaBrowseImportPromise = import( | ||
/* webpackChunkName: "media-player-browse-dialog" */ "../dialogs/media-browse/media-player-browse-dialog" | ||
); | ||
} | ||
return mediaBrowseImportPromise; | ||
}; | ||
|
||
export default <T extends Constructor<HassBaseEl>>(superClass: T) => | ||
class extends superClass { | ||
protected firstUpdated(changedProps: PropertyValues) { | ||
super.firstUpdated(changedProps); | ||
this.addEventListener("hass-media-browse", (ev) => | ||
this._handleMediaBrowse(ev) | ||
); | ||
|
||
// Load it once we are having the initial rendering done. | ||
importMediaBrowse(); | ||
} | ||
|
||
private async _handleMediaBrowse( | ||
ev: HASSDomEvent<MediaPlayerBrowseDialogParams> | ||
) { | ||
showDialog( | ||
this, | ||
this.shadowRoot!, | ||
"media-player-browse-dialog", | ||
ev.detail, | ||
importMediaBrowse | ||
); | ||
} | ||
}; |