Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/workspaces/default-workspace-image-query.ts
2501 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useQuery } from "@tanstack/react-query";
8
import { GetWorkspaceDefaultImageResponse } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
9
import { workspaceClient } from "../../service/public-api";
10
11
export const useWorkspaceDefaultImageQuery = (workspaceId?: string) => {
12
return useQuery<GetWorkspaceDefaultImageResponse | null, Error, GetWorkspaceDefaultImageResponse | undefined>({
13
queryKey: ["default-workspace-image-v2", { workspaceId: workspaceId || "undefined" }],
14
staleTime: 1000 * 60 * 10, // 10 minute
15
queryFn: async () => {
16
if (!workspaceId) {
17
return null; // no workspaceId, no image. Using null because "undefined" is not persisted by react-query
18
}
19
return await workspaceClient.getWorkspaceDefaultImage({ workspaceId });
20
},
21
select: (data) => data || undefined,
22
});
23
};
24
25