Skip to content

Commit

Permalink
chore: merge rc into main (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsANameToo authored Nov 28, 2023
2 parents dc17a91 + 65b0570 commit 1ea76e9
Show file tree
Hide file tree
Showing 112 changed files with 5,985 additions and 2,508 deletions.
11 changes: 10 additions & 1 deletion app/Data/Gallery/GalleryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
use Spatie\LaravelData\PaginatedDataCollection;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;

#[TypeScript]
Expand Down Expand Up @@ -53,6 +54,14 @@ public static function fromModel(Gallery $gallery, ?int $limit = 6): self

$galleryCache = new GalleryCache($gallery);

/** @var PaginatedDataCollection<int, GalleryNftData> */
$nfts = GalleryNftData::collection(
$gallery->nfts()
->with('collection.network', 'collection.floorPriceToken')
->orderByPivot('order_index', 'asc')
->paginate($limit, page: 1)
);

return new self(
id: $gallery->id,
name: $gallery->name,
Expand All @@ -63,7 +72,7 @@ public static function fromModel(Gallery $gallery, ?int $limit = 6): self
collectionsCount: $galleryCache->collectionsCount(),
value: $gallery->value($currency),
coverImage: $gallery->cover_image,
nfts: new GalleryNftsData(GalleryNftData::collection($gallery->nfts()->orderByPivot('order_index', 'asc')->paginate($limit, ['*'], 'page', 1))),
nfts: new GalleryNftsData($nfts),
wallet: SimpleWalletData::fromModel($gallery->user->wallet),
isOwner: $isOwner,
hasLiked: $hasLiked,
Expand Down
34 changes: 34 additions & 0 deletions app/Http/Controllers/Api/UserNftController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api;

use App\Data\Gallery\GalleryNftData;
use App\Http\Controllers\Controller;
use App\Models\Nft;
use App\Models\User;
use Illuminate\Http\Request;
use Spatie\LaravelData\DataCollection;

class UserNftController extends Controller
{
/**
* @return DataCollection<int, GalleryNftData>
*/
public function __invoke(Request $request): DataCollection
{
$ids = array_map(fn ($item) => intval($item), explode(',', $request->get('ids', '') ?? ''));

/** @var User $user */
$user = $request->user();

return GalleryNftData::collection(
$user->nfts()
->whereIn('nfts.id', $ids)
->get()
->sortBy(fn (Nft $nft) => array_search($nft->id, $ids, true))
->values()
);
}
}
22 changes: 22 additions & 0 deletions app/Http/Controllers/Filament/LogoutController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Filament;

use Filament\Facades\Filament;
use Filament\Http\Controllers\Auth\LogoutController as FilamentLogoutController;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class LogoutController extends FilamentLogoutController
{
public function logout(Request $request): RedirectResponse
{
Filament::auth()->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();

return redirect()->route('galleries');
}
}
65 changes: 25 additions & 40 deletions app/Http/Controllers/MyGalleryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,43 @@

namespace App\Http\Controllers;

use App\Data\Gallery\GalleriesData;
use App\Data\Gallery\GalleryCollectionData;
use App\Data\Gallery\GalleryCollectionsData;
use App\Data\Gallery\GalleriesCardData;
use App\Data\Gallery\GalleryCardData;
use App\Data\Gallery\GalleryData;
use App\Data\Gallery\GalleryNftData;
use App\Enums\ToastType;
use App\Http\Controllers\Concerns\StoresGalleries;
use App\Models\Gallery;
use App\Models\Nft;
use App\Models\User;
use App\Repositories\GalleryRepository;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Spatie\LaravelData\PaginatedDataCollection;

class MyGalleryController extends Controller
{
use StoresGalleries;

public function index(Request $request): Response
public function index(Request $request, GalleryRepository $galleries): Response
{
/** @var User $user */
$user = $request->user();

$showDrafts = $request->boolean('draft');

$galleries = $galleries->forUser($user)->through(
fn ($gallery) => GalleryCardData::fromModel($gallery, $user)
);

/** @var PaginatedDataCollection<int, GalleryCardData> */
$collection = GalleryCardData::collection($galleries);

return Inertia::render('Galleries/MyGalleries/Index', [
'title' => trans('metatags.my_galleries.title'),
'galleries' => new GalleriesData(GalleryData::collection($user->galleries()->latest()->paginate(12))),
'nftCount' => $user->nfts->count(),
'title' => $showDrafts ? trans('metatags.my_galleries.title_draft') : trans('metatags.my_galleries.title'),
'galleries' => $showDrafts ? null : new GalleriesCardData($collection),
'nftCount' => $user->nfts()->count(),
'galleryCount' => $user->galleries()->count(),
'showDrafts' => $showDrafts,
]);
}

Expand All @@ -40,24 +49,12 @@ public function create(Request $request): Response|RedirectResponse
/** @var User $user */
$user = $request->user();

$collections = $user
->collections()
->withUserNftsCount($user)
->orderBy('id')
->paginate((int) config('dashbrd.gallery.pagination.collections_per_page'));

$collections->withPath(route('my-galleries.collections'));

$nftsPerPage = (int) config('dashbrd.gallery.pagination.nfts_per_page');

$nfts = Nft::paginatedCollectionNfts($collections, $user, $nftsPerPage);

return Inertia::render('Galleries/MyGalleries/Create', [
'title' => trans('metatags.my_galleries.create.title'),
'nfts' => GalleryNftData::collection($nfts),
'collections' => new GalleryCollectionsData(GalleryCollectionData::collection($collections)),
'nftsPerPage' => $nftsPerPage,
'nftsPerPage' => (int) config('dashbrd.gallery.pagination.nfts_per_page'),
'collectionsPerPage' => (int) config('dashbrd.gallery.pagination.collections_per_page'),
'nftLimit' => config('dashbrd.gallery.nft_limit'),
'nftCount' => $user->nfts()->count(),
]);
}

Expand All @@ -80,28 +77,16 @@ public function edit(Request $request, Gallery $gallery): Response
/** @var User $user */
$user = $request->user();

$collections = $user
->collections()
->withUserNftsCount($user)
->orderBy('id')
->paginate((int) config('dashbrd.gallery.pagination.collections_per_page'));

$collections->withPath(route('my-galleries.collections'));

$nftsPerPage = (int) config('dashbrd.gallery.pagination.nfts_per_page');

$nfts = Nft::paginatedCollectionNfts($collections, $user, $nftsPerPage);

return Inertia::render('Galleries/MyGalleries/Create', [
'title' => trans('metatags.my_galleries.edit.title', ['name' => $gallery->name]),
'nfts' => GalleryNftData::collection($nfts),
'collections' => new GalleryCollectionsData(GalleryCollectionData::collection($collections)),
'gallery' => GalleryData::fromModel(
gallery: $gallery,
limit: config('dashbrd.gallery.nft_limit'),
),
'nftsPerPage' => $nftsPerPage,
'nftsPerPage' => (int) config('dashbrd.gallery.pagination.nfts_per_page'),
'collectionsPerPage' => (int) config('dashbrd.gallery.pagination.collections_per_page'),
'nftLimit' => config('dashbrd.gallery.nft_limit'),
'nftCount' => $user->nfts()->count(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function value(CurrencyCode $currency): ?float
*/
public function collections(): Collection
{
return CollectionModel::whereIn('id', function ($query) {
return CollectionModel::with('network')->whereIn('id', function ($query) {
return $query->select('collection_id')->from('nfts')->whereIn('nfts.id', function ($query) {
return $query->select('nft_id')->from('nft_gallery')->where('gallery_id', $this->id);
});
Expand Down
11 changes: 11 additions & 0 deletions app/Repositories/GalleryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ public function all(?User $user, string $filter, ?string $searchQuery): LengthAw
)->paginate(12);
}

/**
* @return LengthAwarePaginator<Gallery>
*/
public function forUser(User $user): LengthAwarePaginator
{
return $this->modifyQueryForIndex(
query: Gallery::where('user_id', $user->id),
user: $user,
)->paginate(12);
}

/**
* Modify the query instance to apply relationships and limits used on the galleries index page.
*
Expand Down
4 changes: 2 additions & 2 deletions app/Support/Cache/GalleryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function collections(CurrencyCode $currencyCode): DataCollection
{
return $this->fromCache(
fn () => NftCollectionData::collection(
$this->gallery->collections()->map(fn ($collection) => NftCollectionData::fromModel($collection, $currencyCode)
)),
$this->gallery->collections()->map(fn ($collection) => NftCollectionData::fromModel($collection, $currencyCode))
),
self::getCollectionsCacheKey($this->gallery->id, $currencyCode),
[self::TAG_COLLECTIONS, self::TAG_COLLECTIONS.'_'.$this->gallery->id],
);
Expand Down
9 changes: 8 additions & 1 deletion app/Support/NftImageUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ private static function getAlchemyCdn(string $url, ?ImageSize $imageSize): ?stri
$size = 'w_'.$imageSize->width().',h_'.$imageSize->height();
$newPath = preg_replace('/(?<=\/)upload(?=\/)/', "upload/{$size}", $path);

$url = str_replace($path, $newPath, $url);
// Remove the height & replace thumbnailv2, to keep the proper aspect ratio when width is given.
// E.g `w_512,h_512/thumbnailv2` becomes `w_512/scaled`
$scaledPath = preg_replace('/,h_\d+\/thumbnailv2/', '/scaled', $newPath);

// Replace thumbnailv2 for those that don't have dimensions specified (if any).
$scaledPath = preg_replace('/thumbnailv2/', 'scaled', $newPath);

$url = str_replace($path, $scaledPath, $url);
}

return $url;
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,42 @@
"require": {
"php": "^8.2",
"atymic/twitter": "^3.2",
"aws/aws-sdk-php": "^3.283",
"aws/aws-sdk-php": "^3.285",
"cyrildewit/eloquent-viewable": "dev-master",
"filament/filament": "^3.0",
"filament/spatie-laravel-media-library-plugin": "^3.0",
"guzzlehttp/guzzle": "^7.8",
"halaxa/json-machine": "^1.1",
"inertiajs/inertia-laravel": "^0.6",
"jeffgreco13/filament-breezy": "^2.1",
"jeffgreco13/filament-breezy": "^2.2",
"kornrunner/keccak": "^1.1",
"laravel/framework": "^10.29",
"laravel/framework": "^10.31",
"laravel/horizon": "^5.21",
"laravel/pennant": "^1.5",
"laravel/sanctum": "^3.3",
"laravel/slack-notification-channel": "^2.0",
"laravel/telescope": "^4.16",
"laravel/slack-notification-channel": "^2.1",
"laravel/telescope": "^4.17",
"laravel/tinker": "^2.8",
"monolog/monolog": "^3.5",
"sentry/sentry-laravel": "^3.8",
"simplito/elliptic-php": "^1.0",
"spatie/browsershot": "^3.59",
"spatie/laravel-data": "^3.9",
"spatie/laravel-markdown": "^2.4",
"spatie/laravel-medialibrary": "^10.14",
"spatie/laravel-permission": "^5.0",
"spatie/laravel-medialibrary": "^10.15",
"spatie/laravel-permission": "^5.1",
"spatie/laravel-schemaless-attributes": "^2.4",
"spatie/laravel-sluggable": "^3.5",
"spatie/laravel-typescript-transformer": "^2.3",
"staudenmeir/eloquent-eager-limit": "^1.8",
"tightenco/ziggy": "^1.8",
"tightenco/ziggy": "^1.0",
"tpetry/laravel-postgresql-enhanced": "^0.33"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.9",
"fakerphp/faker": "^1.23",
"graham-campbell/analyzer": "^4.0",
"laravel/breeze": "^1.25",
"laravel/breeze": "^1.26",
"laravel/pint": "^1.13",
"laravel/sail": "^1.26",
"mockery/mockery": "^1.6",
Expand Down
Loading

0 comments on commit 1ea76e9

Please sign in to comment.