-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add per_page parameter to page #301
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,57 @@ | ||
<script lang="ts"> | ||
import type { ExtensionByCategoryInfo } from '$lib/api/extensions-info'; | ||
import type { CatalogExtensionInfo, ExtensionByCategoryInfo } from '$lib/api/extensions-info'; | ||
|
||
import ExtensionByCategoryCard from './ExtensionByCategoryCard.svelte'; | ||
import ExtensionsByCategory from './ExtensionsByCategory.svelte'; | ||
|
||
const { extensionsByCategories }: { extensionsByCategories: ExtensionByCategoryInfo[] } = $props(); | ||
interface Props { | ||
extensionsByCategories: ExtensionByCategoryInfo[]; | ||
} | ||
let { extensionsByCategories }: Props = $props(); | ||
|
||
let filteredExtensions = $state<CatalogExtensionInfo[]>([]); | ||
let showCategories = $state<boolean>(true); | ||
|
||
// Get the per_page from the URL | ||
function getPerPageLimit(): number | undefined { | ||
const perPage = new URLSearchParams(window.location.search).get('per_page'); | ||
return perPage ? parseInt(perPage, 10) : undefined; | ||
} | ||
|
||
// Sort extensions based upon the last updated date based upon what's in .versions array | ||
function getSortedExtensions(extensions: CatalogExtensionInfo[]): CatalogExtensionInfo[] { | ||
return [...extensions].sort((a, b) => { | ||
const aLastUpdated = a.versions?.[a.versions.length - 1]?.lastUpdated ?? 0; | ||
const bLastUpdated = b.versions?.[b.versions.length - 1]?.lastUpdated ?? 0; | ||
return Number(bLastUpdated) - Number(aLastUpdated); | ||
}); | ||
} | ||
|
||
$effect(() => { | ||
const limit = getPerPageLimit(); | ||
showCategories = !limit; | ||
|
||
if (limit) { | ||
const allExtensions = extensionsByCategories.flatMap(({ extensions }) => extensions); | ||
filteredExtensions = getSortedExtensions(allExtensions).slice(0, limit); | ||
} | ||
}); | ||
</script> | ||
|
||
<div class="flex flex-col h-full"> | ||
{#each extensionsByCategories as extensionByCategoryInfo} | ||
<ExtensionsByCategory {extensionByCategoryInfo} /> | ||
{/each} | ||
{#if showCategories} | ||
{#each extensionsByCategories as extensionByCategoryInfo} | ||
<ExtensionsByCategory {extensionByCategoryInfo} /> | ||
{/each} | ||
{:else} | ||
<div | ||
class="mt-2 grid min-[920px]:grid-cols-2 min-[1180px]:grid-cols-3 gap-3" | ||
role="region" | ||
aria-label="Filtered extensions" | ||
> | ||
{#each filteredExtensions as extension} | ||
<ExtensionByCategoryCard {extension} /> | ||
{/each} | ||
</div> | ||
{/if} | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (non blocking) but not sure why: looks like we have existing tab characters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, looks like
pnpm format:fix
does not actually do svelte files too