mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 13:01:19 +00:00
fix(platforms): add platforms service + reduce memory consumption when rendering platform cards
This commit is contained in:
parent
d4a36f811b
commit
fe73e9fae9
@ -39,7 +39,6 @@ class Button extends Component
|
||||
'warning' => 'shadow-sm text-black bg-yellow-500 hover:bg-yellow-600',
|
||||
'info' => 'shadow-sm text-white bg-blue-500 hover:bg-blue-600',
|
||||
'disabled' => 'shadow-sm text-black bg-gray-300 cursor-not-allowed',
|
||||
'link' => 'text-accent-base bg-transparent underline hover:no-underline',
|
||||
];
|
||||
|
||||
$sizeClass = [
|
||||
|
20
modules/Platforms/Config/Services.php
Normal file
20
modules/Platforms/Config/Services.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Platforms\Config;
|
||||
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use Modules\Platforms\Platforms;
|
||||
|
||||
class Services extends BaseService
|
||||
{
|
||||
public static function platforms(bool $getShared = true): Platforms
|
||||
{
|
||||
if ($getShared) {
|
||||
return self::getSharedInstance('platforms');
|
||||
}
|
||||
|
||||
return new Platforms();
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@ namespace Modules\Platforms\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
use Modules\Platforms\Entities\Platform;
|
||||
use Modules\Platforms\Platforms;
|
||||
|
||||
class PlatformModel extends Model
|
||||
{
|
||||
@ -55,7 +54,7 @@ class PlatformModel extends Model
|
||||
{
|
||||
$cacheName = "podcast#{$podcastId}_platforms_{$platformType}_withData";
|
||||
if (! ($found = cache($cacheName))) {
|
||||
$platforms = new Platforms();
|
||||
$platforms = service('platforms');
|
||||
|
||||
$found = $this->getPlatforms($podcastId, $platformType);
|
||||
$platformsData = $platforms->getPlatformsByType($platformType);
|
||||
@ -95,7 +94,7 @@ class PlatformModel extends Model
|
||||
{
|
||||
$cacheName = "podcast#{$podcastId}_platforms_{$platformType}";
|
||||
if (! ($found = cache($cacheName))) {
|
||||
$platforms = new Platforms();
|
||||
$platforms = service('platforms');
|
||||
|
||||
/** @var Platform[] $found */
|
||||
$found = $this
|
||||
@ -134,7 +133,7 @@ class PlatformModel extends Model
|
||||
{
|
||||
$this->clearCache($podcastId);
|
||||
|
||||
$platforms = new Platforms();
|
||||
$platforms = service('platforms');
|
||||
|
||||
$platformsData = $platforms->getPlatformsByType($platformType);
|
||||
|
||||
|
@ -22,7 +22,6 @@ use League\HTMLToMarkdown\HtmlConverter;
|
||||
use Modules\Auth\Config\AuthGroups;
|
||||
use Modules\Auth\Models\UserModel;
|
||||
use Modules\Platforms\Models\PlatformModel;
|
||||
use Modules\Platforms\Platforms;
|
||||
use Modules\PodcastImport\Entities\PodcastImportTask;
|
||||
use Modules\PodcastImport\Entities\TaskStatus;
|
||||
use PodcastFeed\PodcastFeed;
|
||||
@ -390,7 +389,7 @@ class PodcastImport extends BaseCommand
|
||||
],
|
||||
];
|
||||
|
||||
$platforms = new Platforms();
|
||||
$platforms = service('platforms');
|
||||
$platformModel = new PlatformModel();
|
||||
foreach ($platformTypes as $platformType) {
|
||||
$platformsData = [];
|
||||
|
@ -39,9 +39,10 @@ parameters:
|
||||
- Modules\PremiumPodcasts\Models\
|
||||
additionalServices:
|
||||
- CodeIgniter\Settings\Config\Services
|
||||
- CodeIgniter\Shield\Config\Services
|
||||
- Michalsn\Uuid\Config\Services
|
||||
- Modules\PremiumPodcasts\Config\Services
|
||||
- Modules\Media\Config\Services
|
||||
- CodeIgniter\Shield\Config\Services
|
||||
- Modules\Platforms\Config\Services
|
||||
ignoreErrors:
|
||||
- '#^Call to an undefined method CodeIgniter\\Cache\\CacheInterface\:\:deleteMatching\(\)#'
|
||||
|
61
themes/cp_admin/podcast/_platform.php
Normal file
61
themes/cp_admin/podcast/_platform.php
Normal file
@ -0,0 +1,61 @@
|
||||
<article class="relative flex-col items-start p-4 rounded-lg bg-elevated border-3 <?= $platform->link_url ? 'border-accent-base' : 'border-subtle' ?>">
|
||||
<?= $platform->link_url ? anchor(
|
||||
route_to(
|
||||
'podcast-platform-remove',
|
||||
$platform->podcast_id,
|
||||
$platform->type,
|
||||
$platform->slug,
|
||||
),
|
||||
icon('delete-bin', 'mx-auto'),
|
||||
[
|
||||
'class' => 'absolute right-0 top-0 -mt-4 -mr-4 p-2 border-red-700 border-2 bg-red-100 rounded-full text-red-700 hover:text-red-900',
|
||||
'data-tooltip' => 'bottom',
|
||||
'title' => lang('Platforms.remove', [
|
||||
'platformName' => $platform->label,
|
||||
]),
|
||||
],
|
||||
)
|
||||
: '' ?>
|
||||
<div class="flex items-center gap-x-2">
|
||||
<?= icon(
|
||||
esc($platform->slug),
|
||||
'text-skin-muted text-4xl',
|
||||
$platform->type
|
||||
) ?>
|
||||
<h2 class="text-xl font-semibold"><?= $platform->label ?></h2>
|
||||
</div>
|
||||
<div class="flex flex-col flex-1 mt-4">
|
||||
<div class="inline-flex ml-8 -mt-6 gap-x-1">
|
||||
<a
|
||||
href="<?= $platform->home_url ?>" class="px-3 py-1 text-xs font-semibold leading-6 underline rounded-full focus:ring-accent text-accent-base hover:no-underline"
|
||||
target="_blank" rel="noopener noreferrer" title="<?= lang('Platforms.home_url', [
|
||||
'platformName' => $platform->label,
|
||||
]) ?>" data-tooltip="bottom"><?= lang('Platforms.website') ?></a>
|
||||
<?php if ($platform->submit_url !== null): ?>
|
||||
<a
|
||||
href="<?= $platform->submit_url ?>" class="px-3 py-1 text-xs font-semibold leading-6 underline rounded-full focus:ring-accent text-accent-base hover:no-underline"
|
||||
target="_blank" rel="noopener noreferrer" title="<?= lang('Platforms.submit_url', [
|
||||
'platformName' => $platform->label,
|
||||
]) ?>" data-tooltip="bottom"><?= lang('Platforms.register') ?></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<fieldset>
|
||||
<Forms.Field
|
||||
label="<?= esc(lang('Platforms.your_link')) ?>"
|
||||
class="w-full mt-4"
|
||||
id="<?= esc($platform->slug) . '_link_url' ?>"
|
||||
name="<?= 'platforms[' . esc($platform->slug) . '][url]' ?>"
|
||||
value="<?= esc($platform->link_url) ?>"
|
||||
type="url"
|
||||
placeholder="https://…" />
|
||||
<Forms.Field
|
||||
label="<?= esc(lang("Platforms.your_id.{$platform->type}")) ?>"
|
||||
class="w-full mt-2"
|
||||
id="<?= esc($platform->slug) . '_account_id' ?>"
|
||||
name="<?= 'platforms[' . esc($platform->slug) . '][account_id]' ?>"
|
||||
value="<?= esc($platform->account_id) ?>"
|
||||
placeholder="<?= lang("Platforms.description.{$platform->type}") ?>" />
|
||||
<Forms.Toggler size="small" class="mt-4 text-sm" id="<?= esc($platform->slug) . '_visible' ?>" name="<?= 'platforms[' . esc($platform->slug) . '][visible]'?>" value="yes" checked="<?= old(esc($platform->slug) . '_visible', $platform->is_visible ? 'true' : 'false') ?>"><?= lang('Platforms.visible') ?></Forms.Toggler>
|
||||
</fieldset>
|
||||
</div>
|
||||
</article>
|
@ -18,67 +18,11 @@
|
||||
<?= csrf_field() ?>
|
||||
|
||||
|
||||
<?php foreach ($platforms as $platform): ?>
|
||||
|
||||
<div class="relative flex-col items-start p-4 rounded-lg bg-elevated border-3 <?= $platform->link_url ? 'border-accent-base' : 'border-subtle' ?>">
|
||||
<?= $platform->link_url ? anchor(
|
||||
route_to(
|
||||
'podcast-platform-remove',
|
||||
$podcast->id,
|
||||
$platform->type,
|
||||
$platform->slug,
|
||||
),
|
||||
icon('delete-bin', 'mx-auto'),
|
||||
[
|
||||
'class' => 'absolute right-0 top-0 -mt-4 -mr-4 p-2 border-red-700 border-2 bg-red-100 rounded-full text-red-700 hover:text-red-900',
|
||||
'data-tooltip' => 'bottom',
|
||||
'title' => lang('Platforms.remove', [
|
||||
'platformName' => $platform->label,
|
||||
]),
|
||||
],
|
||||
)
|
||||
: '' ?>
|
||||
<div class="flex items-center gap-x-2">
|
||||
<?= icon(
|
||||
esc($platform->slug),
|
||||
'text-skin-muted text-4xl',
|
||||
$platform->type
|
||||
) ?>
|
||||
<h2 class="text-xl font-semibold"><?= $platform->label ?></h2>
|
||||
</div>
|
||||
<div class="flex flex-col flex-1 mt-4">
|
||||
<div class="inline-flex ml-8 -mt-6 gap-x-1">
|
||||
<Button uri="<?= $platform->home_url ?>" variant="link" size="small" target="_blank" rel="noopener noreferrer" title="<?= lang('Platforms.home_url', [
|
||||
'platformName' => $platform->label,
|
||||
]) ?>" data-tooltip="bottom"><?= lang('Platforms.website') ?></Button>
|
||||
<?php if ($platform->submit_url !== null): ?>
|
||||
<Button uri="<?= $platform->submit_url ?>" variant="link" size="small" target="_blank" rel="noopener noreferrer" title="<?= lang('Platforms.submit_url', [
|
||||
'platformName' => $platform->label,
|
||||
]) ?>" data-tooltip="bottom"><?= lang('Platforms.register') ?></Button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<fieldset>
|
||||
<Forms.Field
|
||||
label="<?= esc(lang('Platforms.your_link')) ?>"
|
||||
class="w-full mt-4"
|
||||
id="<?= esc($platform->slug) . '_link_url' ?>"
|
||||
name="<?= 'platforms[' . esc($platform->slug) . '][url]' ?>"
|
||||
value="<?= esc($platform->link_url) ?>"
|
||||
type="url"
|
||||
placeholder="https://…" />
|
||||
<Forms.Field
|
||||
label="<?= esc(lang("Platforms.your_id.{$platform->type}")) ?>"
|
||||
class="w-full mt-2"
|
||||
id="<?= esc($platform->slug) . '_account_id' ?>"
|
||||
name="<?= 'platforms[' . esc($platform->slug) . '][account_id]' ?>"
|
||||
value="<?= esc($platform->account_id) ?>"
|
||||
placeholder="<?= lang("Platforms.description.{$platform->type}") ?>" />
|
||||
<Forms.Toggler size="small" class="mt-4 text-sm" id="<?= esc($platform->slug) . '_visible' ?>" name="<?= 'platforms[' . esc($platform->slug) . '][visible]'?>" value="yes" checked="<?= old(esc($platform->slug) . '_visible', $platform->is_visible ? 'true' : 'false') ?>"><?= lang('Platforms.visible') ?></Forms.Toggler>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
<?php foreach ($platforms as $platform) {
|
||||
echo view('podcast/_platform', [
|
||||
'platform' => $platform,
|
||||
]);
|
||||
} ?>
|
||||
|
||||
</form>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user