Skip to content

Commit 1b934ab

Browse files
committed
refactor: clean up props
1 parent ff37ab5 commit 1b934ab

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

site/src/pages/WorkspacesPage/WorkspacesButton.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { type PropsWithChildren, type ReactNode, useState } from "react";
2+
import { useTheme } from "@emotion/react";
23
import { Language } from "./WorkspacesPageView";
3-
4-
import { UseQueryResult } from "@tanstack/react-query";
54
import { type Template } from "api/typesGenerated";
65

76
import { Link as RouterLink } from "react-router-dom";
@@ -21,7 +20,6 @@ import {
2120
PopoverContainer,
2221
PopoverLink,
2322
} from "components/PopoverContainer/PopoverContainer";
24-
import { useTheme } from "@emotion/react";
2523

2624
const ICON_SIZE = 18;
2725
const COLUMN_GAP = 1.5;
@@ -113,25 +111,24 @@ function WorkspaceResultsRow({ template }: { template: Template }) {
113111
}
114112

115113
type WorkspacesButtonProps = PropsWithChildren<{
116-
templatesQuery: UseQueryResult<Template[]>;
114+
isLoadingTemplates: boolean;
115+
templates: readonly Template[];
117116
}>;
118117

119118
export function WorkspacesButton({
120119
children,
121-
templatesQuery,
120+
isLoadingTemplates,
121+
templates,
122122
}: WorkspacesButtonProps) {
123123
const theme = useTheme();
124124

125125
// Dataset should always be small enough that client-side filtering should be
126126
// good enough. Can swap out down the line if it becomes an issue
127127
const [searchTerm, setSearchTerm] = useState("");
128-
const processed = sortTemplatesByUsersDesc(
129-
templatesQuery.data ?? [],
130-
searchTerm,
131-
);
128+
const processed = sortTemplatesByUsersDesc(templates, searchTerm);
132129

133130
let emptyState: ReactNode = undefined;
134-
if (templatesQuery.data?.length === 0) {
131+
if (templates.length === 0) {
135132
emptyState = (
136133
<EmptyState
137134
message="No templates yet"
@@ -175,7 +172,7 @@ export function WorkspacesButton({
175172
paddingY: 1,
176173
}}
177174
>
178-
{status === "loading" ? (
175+
{isLoadingTemplates ? (
179176
<Loader size={14} />
180177
) : (
181178
<>

site/src/pages/WorkspacesPage/WorkspacesPageView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ export const WorkspacesPageView: FC<
7979
<Margins>
8080
<PageHeader
8181
actions={
82-
<WorkspacesButton templatesQuery={templatesQuery}>
82+
<WorkspacesButton
83+
templates={templatesQuery.data ?? []}
84+
isLoadingTemplates={templatesQuery.isLoading}
85+
>
8386
{Language.createWorkspace}
8487
</WorkspacesButton>
8588
}

0 commit comments

Comments
 (0)