mirror of
https://github.com/coder/coder.git
synced 2026-11-03 22:25:31 +08:00
26 lines
727 B
TypeScript
26 lines
727 B
TypeScript
/**
|
|
* @fileoverview TODO: centralize navigation code here! URL constants, URL formatting, all of it
|
|
*/
|
|
|
|
import { useCallback } from "react";
|
|
import type { DashboardValue } from "./dashboard/DashboardProvider";
|
|
import { useDashboard } from "./dashboard/useDashboard";
|
|
|
|
type LinkThunk = (state: DashboardValue) => string;
|
|
|
|
export function useLinks() {
|
|
const dashboard = useDashboard();
|
|
const get = useCallback(
|
|
(thunk: LinkThunk): string => thunk(dashboard),
|
|
[dashboard],
|
|
);
|
|
return get;
|
|
}
|
|
|
|
export const linkToTemplate =
|
|
(organizationName: string, templateName: string): LinkThunk =>
|
|
(dashboard) =>
|
|
dashboard.showOrganizations
|
|
? `/templates/${organizationName}/${templateName}`
|
|
: `/templates/${templateName}`;
|