fix: Display patches using new patches JSON format

This commit is contained in:
oSumAtrIX 2023-10-05 04:55:47 +02:00
parent e290b7c4fd
commit 3c6b6d23f5
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 28 additions and 26 deletions

View File

@ -10,7 +10,8 @@ import type {
DonationPlatform,
CryptoWallet,
Social,
Info
Info,
CompatiblePackage
} from '$lib/types';
export type ReposData = { repositories: Repository[] };
@ -44,7 +45,7 @@ async function patches(): Promise<PatchesData> {
// gets packages and patch count
for (let i = 0; i < json.patches.length; i++) {
json.patches[i].compatiblePackages.forEach((pkg: Patch) => {
json.patches[i].compatiblePackages?.forEach((pkg: CompatiblePackage) => {
packagesWithCount[pkg.name] = (packagesWithCount[pkg.name] || 0) + 1;
});
}

View File

@ -12,11 +12,10 @@ export interface Repository {
export interface Patch {
name: string;
description: string;
version: string;
excluded: boolean;
dependencies: string[];
options: PatchOption[];
compatiblePackages: CompatiblePackage[];
use: boolean;
requiresIntegrations: boolean;
options: PatchOption[];
}
export interface CompatiblePackage {
@ -26,10 +25,10 @@ export interface CompatiblePackage {
export interface PatchOption {
key: string;
default: any;
title: string;
description: string;
required: boolean;
choices: string[];
}
export interface Asset {

View File

@ -47,11 +47,11 @@
if (pkg === '') {
return false;
}
return !!patch.compatiblePackages.find((compat) => compat.name === pkg);
return !!patch.compatiblePackages?.find((compat) => compat.name === pkg);
}
function searchString(str: string, term: string, filter: RegExp) {
return str.toLowerCase().replace(filter, '').includes(term);
function searchString(str?: string, term: string, filter: RegExp) {
return str?.toLowerCase().replace(filter, '').includes(term);
}
function filter(patches: Patch[], pkg: string, search?: string): Patch[] {
@ -70,7 +70,7 @@
return (
searchString(patch.description, search, /\s/g) ||
searchString(patch.name, search, /\s/g) ||
patch.compatiblePackages.find((x) => searchString(x.name, search, /\./g))
patch.compatiblePackages?.find((x) => searchString(x.name, search, /\./g))
);
}
return true;

View File

@ -7,7 +7,7 @@
export let patch: Patch;
export let showAllVersions: boolean;
const hasPatchOptions = !!patch.options.length;
const hasPatchOptions = !!patch.options?.length;
let expanded: boolean = false;
</script>
@ -26,28 +26,30 @@
<img class="expand-arrow" src="/icons/expand_more.svg" alt="dropdown" />
{/if}
</div>
<h5>{patch.description}</h5>
{#if patch.description}
<h5>{patch.description}</h5>
{/if}
<ul class="info-container">
{#each patch.compatiblePackages as pkg}
<a
href="https://play.google.com/store/apps/details?id={pkg.name}"
target="_blank"
rel="noreferrer"
>
<li class="patch-info">📦 {pkg.name}</li>
</a>
{/each}
{#if !patch.compatiblePackages.length}
{#if !patch.compatiblePackages?.length}
<li class="patch-info">🌎 Universal patch</li>
{:else}
{#each patch.compatiblePackages as pkg}
<a
href="https://play.google.com/store/apps/details?id={pkg.name}"
target="_blank"
rel="noreferrer"
>
<li class="patch-info">📦 {pkg.name}</li>
</a>
{/each}
{/if}
{#if hasPatchOptions}
<li class="patch-info">⚙️ Patch options</li>
{/if}
<!-- should i hardcode this to get the version of the first package? idk you cant stop me -->
{#if patch.compatiblePackages.length && patch.compatiblePackages[0].versions.length}
<!-- Should this be hardcoded to get the version of the first package? -->
{#if patch.compatiblePackages?.length && patch.compatiblePackages[0].versions?.length}
{#if showAllVersions}
{#each patch.compatiblePackages[0].versions
.slice()