From abb7fbac276d77b7d31a0aeba75d464f3ba3ad46 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Tue, 28 Sep 2021 15:47:59 +0000 Subject: [PATCH] feat: add DropdownMenu component + remove global audio player in admin --- app/Resources/js/admin-audio-player.ts | 79 +++++++++++++++++++++ app/Views/Components/DropdownMenu.php | 51 +++++++++++++ themes/cp_admin/_layout.php | 46 ++++++------ themes/cp_admin/episode/list.php | 73 +++++++++---------- themes/cp_admin/podcast/latest_episodes.php | 71 +++++++++--------- 5 files changed, 225 insertions(+), 95 deletions(-) create mode 100644 app/Resources/js/admin-audio-player.ts create mode 100644 app/Views/Components/DropdownMenu.php diff --git a/app/Resources/js/admin-audio-player.ts b/app/Resources/js/admin-audio-player.ts new file mode 100644 index 00000000..28460b89 --- /dev/null +++ b/app/Resources/js/admin-audio-player.ts @@ -0,0 +1,79 @@ +import { + VmAudio, + VmCaptions, + VmClickToPlay, + VmControl, + VmControls, + VmCurrentTime, + VmDefaultControls, + VmDefaultSettings, + VmDefaultUi, + VmEndTime, + VmFile, + VmIcon, + VmIconLibrary, + VmLoadingScreen, + VmMenu, + VmMenuItem, + VmMenuRadio, + VmMenuRadioGroup, + VmMuteControl, + VmPlaybackControl, + VmPlayer, + VmScrubberControl, + VmSettings, + VmSettingsControl, + VmSkeleton, + VmSlider, + VmSubmenu, + VmTime, + VmTimeProgress, + VmTooltip, + VmUi, + VmVolumeControl, +} from "@vime/core"; +import "@vime/core/themes/default.css"; +import "@vime/core/themes/light.css"; +import "./modules/play-episode-button"; + +// Register Castopod's icons library +const library: HTMLVmIconLibraryElement | null = document.querySelector( + 'vm-icon-library[name="castopod-icons"]' +); +if (library) { + library.resolver = (iconName) => `/assets/icons/${iconName}.svg`; +} + +// Vime elements for audio player +customElements.define("vm-player", VmPlayer); +customElements.define("vm-file", VmFile); +customElements.define("vm-audio", VmAudio); +customElements.define("vm-ui", VmUi); +customElements.define("vm-default-ui", VmDefaultUi); +customElements.define("vm-click-to-play", VmClickToPlay); +customElements.define("vm-captions", VmCaptions); +customElements.define("vm-loading-screen", VmLoadingScreen); +customElements.define("vm-default-controls", VmDefaultControls); +customElements.define("vm-default-settings", VmDefaultSettings); +customElements.define("vm-controls", VmControls); +customElements.define("vm-playback-control", VmPlaybackControl); +customElements.define("vm-volume-control", VmVolumeControl); +customElements.define("vm-scrubber-control", VmScrubberControl); +customElements.define("vm-current-time", VmCurrentTime); +customElements.define("vm-end-time", VmEndTime); +customElements.define("vm-settings-control", VmSettingsControl); +customElements.define("vm-time-progress", VmTimeProgress); +customElements.define("vm-control", VmControl); +customElements.define("vm-icon", VmIcon); +customElements.define("vm-icon-library", VmIconLibrary); +customElements.define("vm-tooltip", VmTooltip); +customElements.define("vm-mute-control", VmMuteControl); +customElements.define("vm-slider", VmSlider); +customElements.define("vm-time", VmTime); +customElements.define("vm-menu", VmMenu); +customElements.define("vm-menu-item", VmMenuItem); +customElements.define("vm-submenu", VmSubmenu); +customElements.define("vm-menu-radio-group", VmMenuRadioGroup); +customElements.define("vm-menu-radio", VmMenuRadio); +customElements.define("vm-settings", VmSettings); +customElements.define("vm-skeleton", VmSkeleton); diff --git a/app/Views/Components/DropdownMenu.php b/app/Views/Components/DropdownMenu.php new file mode 100644 index 00000000..f83712c2 --- /dev/null +++ b/app/Views/Components/DropdownMenu.php @@ -0,0 +1,51 @@ +items = json_decode(html_entity_decode($value), true); + } + + public function render(): string + { + if ($this->items === []) { + throw new Exception('Dropdown menu has no items'); + } + + $menuItems = ''; + foreach ($this->items as $item) { + switch ($item['type']) { + case 'link': + $menuItems .= anchor($item['uri'], $item['title'], [ + 'class' => 'px-4 py-1 hover:bg-gray-100' . (array_key_exists('class', $item) ? ' ' . $item['class'] : ''), + ]); + break; + case 'separator': + $menuItems .= '
'; + break; + default: + break; + } + } + + return <<{$menuItems} + HTML; + } +} diff --git a/themes/cp_admin/_layout.php b/themes/cp_admin/_layout.php index 1950c5de..f6b47bd4 100644 --- a/themes/cp_admin/_layout.php +++ b/themes/cp_admin/_layout.php @@ -14,7 +14,7 @@ asset('js/admin.ts', 'js') ?> asset('js/audio-player.ts', 'js') ?> + ->asset('js/admin-audio-player.ts', 'js') ?> @@ -40,28 +40,26 @@ data-dropdown="button" data-dropdown-target="my-account-dropdown-menu" aria-haspopup="true" - aria-expanded="false"> - - username ?> - - - + aria-expanded="false">username . icon('caret-down', 'ml-auto text-2xl') ?> +
-
+
diff --git a/themes/cp_admin/episode/list.php b/themes/cp_admin/episode/list.php index ea736f12..42577e05 100644 --- a/themes/cp_admin/episode/list.php +++ b/themes/cp_admin/episode/list.php @@ -74,44 +74,45 @@ [ 'header' => lang('Episode.list.actions'), 'cell' => function ($episode, $podcast) { - return '' . - '' . - '
'; + ''; }, ], ], diff --git a/themes/cp_admin/podcast/latest_episodes.php b/themes/cp_admin/podcast/latest_episodes.php index 3a0cb19c..2d795036 100644 --- a/themes/cp_admin/podcast/latest_episodes.php +++ b/themes/cp_admin/podcast/latest_episodes.php @@ -52,41 +52,42 @@ aria-haspopup="true" aria-expanded="false" > - +