Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions apps/builder/app/builder/features/address-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,16 @@ import {
MenuList,
} from "@webstudio-is/design-system";
import { CheckMarkIcon, CopyIcon, DynamicPageIcon } from "@webstudio-is/icons";
import {
findParentFolderByChildId,
ROOT_FOLDER_ID,
getPagePath,
} from "@webstudio-is/sdk";
import { $pages, $publishedOrigin } from "~/shared/nano-states";
import { $publishedOrigin } from "~/shared/nano-states";
import {
compilePathnamePattern,
isPathnamePattern,
matchPathnamePattern,
tokenizePathnamePattern,
} from "~/builder/shared/url-pattern";
import { $selectedPage } from "~/shared/awareness";
import { $selectedPage, $selectedPagePath } from "~/shared/awareness";
import { $currentSystem, updateCurrentSystem } from "~/shared/system";

const $selectedPagePath = computed([$selectedPage, $pages], (page, pages) => {
if (pages === undefined || page === undefined) {
return "/";
}
const parentFolder = findParentFolderByChildId(page.id, pages.folders);
const parentFolderId = parentFolder?.id ?? ROOT_FOLDER_ID;
const foldersPath = getPagePath(parentFolderId, pages);
return [foldersPath, page?.path ?? ""]
.filter(Boolean)
.join("/")
.replace(/\/+/g, "/");
});

const $selectedPageHistory = computed(
$selectedPage,
(page) => page?.history ?? []
Expand Down
18 changes: 15 additions & 3 deletions apps/builder/app/builder/features/topbar/publish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { validateProjectDomain, type Project } from "@webstudio-is/project";
import {
$awareness,
$selectedPagePath,
findAwarenessByInstanceId,
type Awareness,
} from "~/shared/awareness";
Expand Down Expand Up @@ -95,11 +96,15 @@ const ChangeProjectDomain = ({
}: ChangeProjectDomainProps) => {
const id = useId();
const publishedOrigin = useStore($publishedOrigin);
const selectedPagePath = useStore($selectedPagePath);

const [domain, setDomain] = useState(project.domain);
const [error, setError] = useState<string>();
const [isUpdateInProgress, setIsUpdateInProgress] = useOptimistic(false);

const pageUrl = new URL(publishedOrigin);
pageUrl.pathname = selectedPagePath;

const updateProjectDomain = async () => {
setIsUpdateInProgress(true);
const validationResult = validateProjectDomain(domain);
Expand Down Expand Up @@ -138,7 +143,7 @@ const ChangeProjectDomain = ({

return (
<CollapsibleDomainSection
title={new URL(publishedOrigin).host}
title={pageUrl.host}
prefix={
<DomainCheckbox
defaultChecked={project.latestBuildVirtual?.domain === domain}
Expand Down Expand Up @@ -171,11 +176,18 @@ const ChangeProjectDomain = ({
)}
</Flex>
</Tooltip>
<Tooltip content={`Proceed to ${publishedOrigin}`}>
<Tooltip
content={
<Text css={{ wordBreak: "break-all" }}>
Proceed to ${pageUrl.toString()}
</Text>
}
variant="wrapped"
>
<IconButton
tabIndex={-1}
onClick={(event) => {
window.open(publishedOrigin, "_blank");
window.open(pageUrl, "_blank");
event.preventDefault();
}}
>
Expand Down
19 changes: 19 additions & 0 deletions apps/builder/app/shared/awareness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
type Page,
rootComponent,
Pages,
findParentFolderByChildId,
getPagePath,
ROOT_FOLDER_ID,
} from "@webstudio-is/sdk";
import { $pages } from "./nano-states/pages";
import { $instances, $selectedInstanceSelector } from "./nano-states/instances";
Expand All @@ -33,6 +36,22 @@ export const $selectedPage = computed(
}
);

export const $selectedPagePath = computed(
[$selectedPage, $pages],
(page, pages) => {
if (pages === undefined || page === undefined) {
return "/";
}
const parentFolder = findParentFolderByChildId(page.id, pages.folders);
const parentFolderId = parentFolder?.id ?? ROOT_FOLDER_ID;
const foldersPath = getPagePath(parentFolderId, pages);
return [foldersPath, page?.path ?? ""]
.filter(Boolean)
.join("/")
.replace(/\/+/g, "/");
}
);

export const $temporaryInstances = atom<Instances>(new Map());
export const addTemporaryInstance = (instance: Instance) => {
$temporaryInstances.get().set(instance.id, instance);
Expand Down