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

View File

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

View File

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

View File

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