Skip to content

Commit

Permalink
fix: iframe preview urls (#123)
Browse files Browse the repository at this point in the history
* chore: add files to package.json

* chore: publish 0.0.31-preview

* chore: update files

* chore: publish 0.0.31-preview.1

* fix: try replacing react-router-dom search param creation

* chore: publish 0.0.31-preview.2

* fix: remove useMemo, add console logs

* chore: publish 0.0.31-preview.3

* fix: try moving context up one level

* chore: publish 0.0.31-preview.4

* fix: remove console.logs

* fix: filter empty url records
  • Loading branch information
jonambas authored Nov 11, 2023
1 parent 18fbf18 commit 826b4db
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
cypress
cypress.config.ts
.github
lib

.eslintrc
.prettierrc
renovate.json
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sweatpants/libra",
"version": "0.0.30",
"version": "0.0.31-preview.4",
"description": "",
"publishConfig": {
"access": "public"
Expand All @@ -10,6 +10,16 @@
"bin": {
"libra": "dist/cli.mjs"
},
"files": [
"assets",
"api",
"dist",
"lib",
"src",
"types",
"index.html",
"preview.html"
],
"scripts": {
"build": "rimraf dist && rollup -c && npm run prepare:panda",
"build:w": "rimraf dist && rollup -c -w",
Expand Down
4 changes: 3 additions & 1 deletion src/main/components/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { Open } from '../icons';
import { css } from '../../lb-system/css';
import { SettingsContext } from '../context/settings';
import { useUrl } from '../hooks/useUrl';
import { LibraContext } from '../context/libra';

export const Toolbar: FC = () => {
const { hideSidebar, toggleSidebar, setColorChoice, colorChoice } =
useContext(SettingsContext);
const { activeId } = useContext(LibraContext);

const url = useUrl({ preview: true });
const url = useUrl({ id: activeId, preview: true });

return (
<div
Expand Down
32 changes: 6 additions & 26 deletions src/main/hooks/useUrl.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
import { useContext, useMemo } from 'react';
import { createSearchParams } from 'react-router-dom';
import { LibraContext } from '../context/libra';
import { useColorScheme } from '@sweatpants/react';

interface UseUrlOptions {
preview?: boolean;
id?: string;
}

const filterObject = (obj: Record<string, any>) => {
return Object.keys(obj).reduce((acc, key) => {
if (obj[key]) {
return { ...acc, [key]: obj[key] };
}
return acc;
}, {});
};

export const useUrl = ({ preview, id }: UseUrlOptions = {}): string => {
const { activeId, scheme } = useContext(LibraContext);
const [scheme] = useColorScheme();

const params = useMemo(
() =>
createSearchParams(
new URLSearchParams(
filterObject({
entry: id || activeId,
scheme
})
)
),
[id, activeId, scheme]
);
const params = new URLSearchParams({
...(id ? { entry: id } : {}),
...(scheme ? { scheme: scheme } : {})
}).toString();

const path = preview ? '/preview.html' : '/';

return `${path}?${params}`;
};

1 comment on commit 826b4db

@vercel
Copy link

@vercel vercel bot commented on 826b4db Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

libra – ./

libra-git-main-jambas.vercel.app
libra-jambas.vercel.app
libra-test.vercel.app

Please sign in to comment.