Skip to content

Commit

Permalink
fix: store
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Sep 18, 2024
1 parent d5c0626 commit 0defd3c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/cli-app/src/api/stores/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { getStores } from "@next-boilerplate/cli-helpers/stores-helpers"
import { getStoresRequestSchema, getStoresResponseSchema } from "./schemas"

export const getStoresQuery = async ({
input: { onlyInstalled },
input: { onlyInstalled, search },
}: apiInputFromSchema<typeof getStoresRequestSchema>) => {
try {
let stores = await getStores({ assetsDirectory })
let stores = await getStores({ assetsDirectory, search })
const configuration = await getConfiguration()

// Filter to get stores that are already in the configuration
Expand Down
1 change: 1 addition & 0 deletions packages/cli-app/src/api/stores/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fullStoreSchema, storeConfigSchema } from "@next-boilerplate/cli-helper

export const getStoresRequestSchema = () =>
z.object({
search: z.string().optional(),
onlyInstalled: z.boolean().optional(),
})

Expand Down
19 changes: 15 additions & 4 deletions packages/cli-app/src/app/plugins/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Header from "@/components/ui/header"
import { TDictionary } from "@/lib/langs"
import { trpc } from "@/lib/trpc/client"
import { RouterOutputs } from "@/lib/trpc/utils"
import { cn } from "@/lib/utils"
import { getItemUID } from "@next-boilerplate/cli-helpers/stores"
import { Input } from "@nextui-org/input"
import { Link } from "@nextui-org/link"
Expand Down Expand Up @@ -86,17 +87,24 @@ export default function PluginsContent({
}, [plugins.data])

const stores = trpc.stores.getStores.useQuery(
{ onlyInstalled: true },
{ onlyInstalled: true, search: _search },
{
initialData: ssrStores,
initialData: isInitialFilter ? ssrStores : undefined,
}
)

const [storesData, setStoresData] = useState(ssrStores)
useEffect(() => {
if (stores.data) {
setStoresData(stores.data)
}
}, [stores.data])

if (!storeName || !storeVersion) {
return (
<ChooseStore
dictionary={dictionary}
stores={stores.data}
stores={storesData}
isLoading={stores.isLoading}
search={search}
setSearch={setSearch}
Expand Down Expand Up @@ -137,7 +145,10 @@ export default function PluginsContent({
/>
)
}
isDisabled={plugins.isLoading}
className={cn("w-64", {
"opacity-50": plugins.isLoading,
})}
isReadOnly={plugins.isLoading}
/>
}
/>
Expand Down
35 changes: 30 additions & 5 deletions packages/cli-app/src/app/templates/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import ItemCard from "@/components/ui/item-card"
import { TDictionary } from "@/lib/langs"
import { trpc } from "@/lib/trpc/client"
import { RouterOutputs } from "@/lib/trpc/utils"
import { cn } from "@/lib/utils"
import { getItemUID } from "@next-boilerplate/cli-helpers/stores"
import { Input } from "@nextui-org/input"
import { Link } from "@nextui-org/link"
import { Spinner } from "@nextui-org/spinner"

import { TemplatesContentDr } from "./content.dr"

type TTemplates = RouterOutputs["templates"]["getTemplates"]

export default function TemplatesContent({
initialStoreName,
initialStoreVersion,
Expand Down Expand Up @@ -69,18 +72,37 @@ export default function TemplatesContent({
}
)

// Do not set empty data to the cache
const [templatesData, setTemplatesData] = useState<TTemplates>(
ssrTemplates ?? {
templates: [],
}
)
useEffect(() => {
if (templates.data) {
setTemplatesData(templates.data)
}
}, [templates.data])

const stores = trpc.stores.getStores.useQuery(
{ onlyInstalled: true },
{ onlyInstalled: true, search: _search },
{
initialData: ssrStores,
initialData: isInitialFilter ? ssrStores : undefined,
}
)

const [storesData, setStoresData] = useState(ssrStores)
useEffect(() => {
if (stores.data) {
setStoresData(stores.data)
}
}, [stores.data])

if (!storeName || !storeVersion) {
return (
<ChooseStore
dictionary={dictionary}
stores={stores.data}
stores={storesData}
isLoading={stores.isLoading}
search={search}
setSearch={setSearch}
Expand Down Expand Up @@ -121,12 +143,15 @@ export default function TemplatesContent({
/>
)
}
isDisabled={templates.isLoading}
className={cn("w-64", {
"opacity-50": templates.isLoading,
})}
isReadOnly={templates.isLoading}
/>
}
/>
<ul className="flex flex-1 flex-col gap-2">
{templates.data?.templates.map((template) => (
{templatesData.templates.map((template) => (
<ItemCard
key={getItemUID(template)}
id={getItemUID(template)}
Expand Down
49 changes: 35 additions & 14 deletions packages/cli-app/src/components/choose-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Store } from "lucide-react"

import { TDictionary } from "@/lib/langs"
import { RouterOutputs } from "@/lib/trpc/utils"
import { cn } from "@/lib/utils"
import { Input } from "@nextui-org/input"
import { Spinner } from "@nextui-org/spinner"

import Header from "./ui/header"
import ItemCard from "./ui/item-card"
Expand All @@ -17,7 +19,7 @@ export default function ChooseStore({
lnk,
}: {
dictionary: TDictionary<typeof ChooseStoreDr>
stores: RouterOutputs["stores"]["getStores"] | undefined
stores: RouterOutputs["stores"]["getStores"]
isLoading: boolean
search: string
setSearch: (search: string) => void
Expand All @@ -28,21 +30,40 @@ export default function ChooseStore({
<Header
title={dictionary.selectStore}
dictionary={dictionary}
actions={<Input value={search} onValueChange={setSearch} placeholder={dictionary.search} />}
actions={
<Input
value={search}
onValueChange={setSearch}
placeholder={dictionary.search}
endContent={
isLoading && (
<Spinner
classNames={{
wrapper: "!size-4",
}}
color="current"
size="sm"
/>
)
}
className={cn("w-64", {
"opacity-50": isLoading,
})}
isReadOnly={isLoading}
/>
}
/>
<ul className="flex flex-1 flex-col gap-2">
{isLoading
? [...Array(5)].map((_, i) => <ItemCard key={i} isLoading id="" title="" description="" />)
: stores?.stores.map((store) => (
<ItemCard
key={store.uid}
id={store.uid}
title={store.name}
description={dictionary.storeVersion + ": " + store.version}
href={`${lnk}?storeName=${encodeURIComponent(store.name)}&storeVersion=${encodeURIComponent(store.version)}`}
endContent={<Store className="absolute right-2 top-2 size-4 text-primary" />}
/>
))}
{stores.stores.map((store) => (
<ItemCard
key={store.uid}
id={store.uid}
title={store.name}
description={dictionary.storeVersion + ": " + store.version}
href={`${lnk}?storeName=${encodeURIComponent(store.name)}&storeVersion=${encodeURIComponent(store.version)}`}
endContent={<Store className="absolute right-2 top-2 size-4 text-primary" />}
/>
))}
</ul>
</>
)
Expand Down

0 comments on commit 0defd3c

Please sign in to comment.