Skip to content

Commit

Permalink
defers star loading
Browse files Browse the repository at this point in the history
  • Loading branch information
syropian committed Jun 26, 2024
1 parent 7732ff5 commit 11f713e
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 27 deletions.
13 changes: 9 additions & 4 deletions app/Data/DashboardData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
namespace App\Data;

use App\Models\User;
use Hybridly\Support\Deferred;
use Illuminate\Support\Collection;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\CamelCaseMapper;
use Spatie\TypeScriptTransformer\Attributes\LiteralTypeScriptType;

use function Hybridly\deferred;

#[MapOutputName(CamelCaseMapper::class)]
class DashboardData extends Data
{
public function __construct(
/** @var Collection<int, TagData> */
public Collection $tags,
#[LiteralTypeScriptType('Array<App.Data.StarData>')]
/** @var Collection<int, StarData> */
public Collection $stars,
public Deferred $stars,
/** @var Collection<int, SmartFilterData> */
public Collection $smart_filters,
) {
Expand All @@ -26,9 +31,9 @@ public function __construct(
public static function fromModel(User $user): self
{
return new self(
TagData::collect($user->tags()->withStarCount()->get()),
StarData::collect($user->stars()->with('tags')->get()),
SmartFilterData::collect($user->smartFilters),
tags: TagData::collect($user->tags()->withStarCount()->get()),
stars: deferred(fn () => StarData::collect($user->stars()->with('tags')->get())),
smart_filters: SmartFilterData::collect($user->smartFilters),
);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Http\Controllers;

use App\Data\UpdateUserSettingsRequest;
use App\Requests\UpdateUserSettingsRequest;

class UserSettingsController extends Controller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Data;
namespace App\Requests;

use App\Models\User;
use Spatie\LaravelData\Attributes\Validation\In;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"nanoid": "^3.1.30",
"pinia": "^2.0.29",
"sortablejs": "^1.15.0",
"sortablejs-vue3": "^1.2.2",
"sortablejs-vue3": "^1.2.11",
"tiptap-markdown": "^0.8.9",
"vue": "^3.3.4",
"vue-confetti-explosion": "^1.0.2",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSettingsDialog } from '@/composables/useSettingsDialog'
import { useUserStore } from '@/store/useUserStore'
import { SettingsTab } from '@/types'
import { DialogTitle } from '@headlessui/vue'
import { CheckCircleIcon, XCircleIcon } from '@heroicons/vue/24/solid'
import { CheckCircleIcon } from '@heroicons/vue/24/solid'
import { router } from 'hybridly'
import { computed, nextTick, ref } from 'vue'
import ConfettiExplosion from 'vue-confetti-explosion'
Expand Down Expand Up @@ -63,7 +63,8 @@ const deleteUser = async () => {
}
}
const isSponsor = ref(false)
const isSponsor = ref(user.value?.isSponsor ?? false)
const checkSponsorshipStatus = () => {
isSponsor.value = true
}
Expand Down
9 changes: 2 additions & 7 deletions resources/components/sidebar/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ import SidebarSmartFilter from '@/components/sidebar/SidebarSmartFilter.vue'
import SidebarTag from '@/components/sidebar/SidebarTag.vue'
import SortTagsMenu from '@/components/sidebar/SortTagsMenu.vue'
import { useAuth } from '@/composables/use-auth'
import { ToastType, useGlobalToast } from '@/composables/useGlobalToast'
import { useSmartFilterDialog } from '@/composables/useSmartFilterDialog'
import { useSponsorshipDialog } from '@/composables/useSponsorshipDialog'
import { SPONSORSHIP_REQUIRED_ERROR } from '@/constants'
import { useSmartFiltersStore } from '@/store/useSmartFiltersStore'
import { useStarsFilterStore } from '@/store/useStarsFilterStore'
import { useStarsStore } from '@/store/useStarsStore'
import { useTagsStore } from '@/store/useTagsStore'
import { Ability, Errors, StarDragDataTransferData } from '@/types'
import { getNavigationResponseErrors } from '@/utils'
// import { Errors } from '@inertiajs/core'
import { ArrowPathIcon, InboxIcon, PlusCircleIcon, StarIcon } from '@heroicons/vue/24/outline'
import { Ability, StarDragDataTransferData } from '@/types'
import { router } from 'hybridly'
import { Sortable } from 'sortablejs-vue3'
import { computed, nextTick, reactive, ref } from 'vue'
Expand Down Expand Up @@ -98,7 +93,7 @@ const doShowSmartFilterDialog = () => {
const toggleSidebarGroupCollapsedState = async (key: CollapsibleSidebarSettingsKey) => {
sidebarGroupCollapsedState[key] = !sidebarGroupCollapsedState[key]
const data: App.Data.UpdateUserSettingsRequest = {
const data: App.Requests.UpdateUserSettingsRequest = {
enabled: sidebarGroupCollapsedState[key],
key,
}
Expand Down
2 changes: 0 additions & 2 deletions resources/components/stars/StarredRepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useAuth } from '@/composables/use-auth'
import { useStarsStore } from '@/store/useStarsStore'
import { useTagsStore } from '@/store/useTagsStore'
import { GitHubRepo, GitHubRepoNode, StarMetaInput, TagEditorTag } from '@/types'
// import { GlobeAmericasIcon as GlobeIcon, ShareIcon, StarIcon } from '@heroicons/vue/16/solid'
import pick from 'lodash/pick'
import { computed, ref } from 'vue'
Expand Down Expand Up @@ -220,7 +219,6 @@ const onDragEnd = () => {
/>
</svg>
<!-- <span class="group-hover/repo-link:underline ml-0.5 text-sm font-medium">Visit</span> -->
<span class="sr-only">Visit</span>
</a>
</div>
Expand Down
6 changes: 1 addition & 5 deletions resources/views/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ import { useStarsStore } from '@/store/useStarsStore'
import { useTagsStore } from '@/store/useTagsStore'
import { useUserStore } from '@/store/useUserStore'
import { GitHubRepo } from '@/types'
import {
ArrowLeftCircleIcon,
XCircleIcon as CloseIcon,
Bars3CenterLeftIcon as MenuIcon,
} from '@heroicons/vue/24/outline'
import { ArrowLeftCircleIcon, Bars3CenterLeftIcon as MenuIcon } from '@heroicons/vue/24/outline'
import { tryOnMounted } from '@vueuse/core'
import localForage from 'localforage'
import { computed, nextTick, ref, watch } from 'vue'
Expand Down

0 comments on commit 11f713e

Please sign in to comment.