show link when no search results (#504)

This commit is contained in:
ABevier 2023-04-25 21:51:51 -04:00 committed by GitHub
parent 15e21b7ca3
commit f4939bee51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 33 deletions

View file

@ -100,12 +100,12 @@ function newInstallProgressNotifier(full_name: string, notifyMainWindow: MainWin
// how much of the current package is completed // how much of the current package is completed
const packageProgress = (received / contentSize) * 100; const packageProgress = (received / contentSize) * 100;
// progress is the total packages completed plus the percentage of the current package // progress is the total packages completed plus the percentage of the current package
const progress = (overallProgress + packageProgress / numberOfPackages).toFixed(2); const progress = overallProgress + packageProgress / numberOfPackages;
notifyMainWindow("install-progress", { full_name, progress }); notifyMainWindow("install-progress", { full_name, progress });
} }
} else if (msg.status === "installed") { } else if (msg.status === "installed") {
currentPackageNumber++; currentPackageNumber++;
const progress = ((currentPackageNumber / numberOfPackages) * 100).toFixed(2); const progress = (currentPackageNumber / numberOfPackages) * 100;
notifyMainWindow("install-progress", { full_name, progress }); notifyMainWindow("install-progress", { full_name, progress });
} }
}; };

View file

@ -142,7 +142,7 @@
{/if} {/if}
{#if pkg.github} {#if pkg.github}
<button <button
class="border-gray group flex h-[40px] w-[40px] items-center justify-center rounded-sm border hover:bg-[#e1e1e1]" class="border-gray group flex h-[40px] w-[40px] items-center justify-center rounded-sm border hover:bg-[#e1e1e1] shrink-0"
on:click={() => { on:click={() => {
if (pkg.github) { if (pkg.github) {
const slug = trimGithubSlug(pkg.github); const slug = trimGithubSlug(pkg.github);

View file

@ -0,0 +1,15 @@
<script lang="ts">
import Button from "@tea/ui/button/button.svelte";
import { shellOpenExternal } from "@native";
</script>
<div class="flex flex-col justify-center items-center h-full">
<div class="text-2xl">Hmm, we don't have that one yet...</div>
<div class="text-xl mt-4">But we'd love for you to submit it to the pantry!</div>
<div class="mt-10">
<Button type="plain" color="blue" onClick={() => shellOpenExternal("https://github.com/teaxyz/pantry")}>
<span class="text-sm px-12">VISIT PANTRY</span>
</Button>
</div>
<div class="text-gray text-xs mt-2">Redirects to github</div>
</div>

View file

@ -12,6 +12,7 @@
import { installPackage } from "@native"; import { installPackage } from "@native";
import { onMount } from "svelte"; import { onMount } from "svelte";
import NoSearchResults from "./no-search-results.svelte";
const { searching, packagesSearch } = searchStore; const { searching, packagesSearch } = searchStore;
// import type { AirtablePost } from '@tea/ui/types'; // import type { AirtablePost } from '@tea/ui/types';
@ -75,33 +76,35 @@
</header> </header>
{#if term} {#if term}
<div class="z-20 bg-black"> <div class="z-20 bg-black">
<header class="text-gray p-4 text-lg"> {#if $packagesSearch.length > 0}
Packages ({$packagesSearch.length}) <header class="text-gray p-4 text-lg">
</header> packages ({$packagesSearch.length})
<ul class="flex flex-col gap-2 p-2"> </header>
{#if $packagesSearch.length > 0} <ul class="flex flex-col gap-2 p-2">
{#each $packagesSearch as pkg} {#each $packagesSearch as pkg}
<div class={pkg.state === PackageStates.INSTALLING ? "animate-pulse" : ""}> <div class={pkg.state === PackageStates.INSTALLING ? "animate-pulse" : ""}>
<PackageResult <PackageResult
{pkg} {pkg}
{onClose} {onClose}
onClick={async () => { onClick={async () => {
if ( if (
[ [
PackageStates.INSTALLED, PackageStates.INSTALLED,
PackageStates.INSTALLING, PackageStates.INSTALLING,
PackageStates.UPDATING PackageStates.UPDATING
].includes(pkg.state) ].includes(pkg.state)
) { ) {
return; return;
} }
packagesStore.installPkg(pkg); packagesStore.installPkg(pkg);
}} }}
/> />
</div> </div>
{/each} {/each}
{/if} </ul>
</ul> {:else}
<NoSearchResults />
{/if}
<!-- <header class="text-primary p-4 text-lg"> <!-- <header class="text-primary p-4 text-lg">
Top Article Results ({articles.length}) Top Article Results ({articles.length})
</header> </header>

View file

@ -36,6 +36,7 @@
onFocus={() => { onFocus={() => {
searchStore.searching.set(true); searchStore.searching.set(true);
}} }}
readonly={true}
/> />
<kbd <kbd

View file

@ -318,7 +318,7 @@ export const withFakeLoader = (
const progressLeft = 100 - fakeLoadingProgress; const progressLeft = 100 - fakeLoadingProgress;
const addProgress = progressLeft * increment; const addProgress = progressLeft * increment;
fakeLoadingProgress = fakeLoadingProgress + addProgress; fakeLoadingProgress = fakeLoadingProgress + addProgress;
callback(+fakeLoadingProgress.toFixed(2)); callback(fakeLoadingProgress);
}, ms); }, ms);
return fakeTimer; return fakeTimer;

View file

@ -5,7 +5,7 @@
</script> </script>
<button <button
class="group flex h-[28px] w-[28px] items-center justify-center rounded-sm border border-gray hover:bg-[#e1e1e1]" class="group flex h-[28px] w-[28px] shrink-0 items-center justify-center rounded-sm border border-gray hover:bg-[#e1e1e1]"
on:dblclick={preventDoubleClick} on:dblclick={preventDoubleClick}
on:click on:click
title={helpText} title={helpText}

View file

@ -18,6 +18,12 @@
return path; return path;
} }
}; };
// Format the percentage expressed as 0..100 to a number with 2 decimal places.
// we never want to round 99.999% to 100% because makes the experience bad so we can't just use toFixed(2) immediately
const formatPercent = (percent: number) => {
return (Math.floor(percent * 100) / 100).toFixed(2);
};
</script> </script>
<div> <div>
@ -27,7 +33,7 @@
</svg> </svg>
<div> <div>
<slot> <slot>
<span>{value}%</span> <span class="font-mono">{formatPercent(value)}%</span>
</slot> </slot>
</div> </div>
</div> </div>

View file

@ -15,6 +15,7 @@
export let placeholder = "search_"; export let placeholder = "search_";
export let autofocus = false; export let autofocus = false;
export let readonly = false;
let searchInput: HTMLInputElement; let searchInput: HTMLInputElement;
@ -58,6 +59,7 @@
{placeholder} {placeholder}
on:keyup={onChange} on:keyup={onChange}
on:focus={onFocus} on:focus={onFocus}
{readonly}
/> />
</section> </section>