Skip to content

Commit

Permalink
fix: update modal
Browse files Browse the repository at this point in the history
  • Loading branch information
crherman7 committed Nov 4, 2024
1 parent 2456d67 commit b207b3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
40 changes: 5 additions & 35 deletions packages/app-router/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ export function useModal<T, U>() {
}

return {
// The data passed to the modal, cast to the type T
data: state.data as T,

// A function to resolve the modal with a result of type U
resolve: state.resolve(componentId) as (result: U) => void,

Expand Down Expand Up @@ -237,33 +234,6 @@ export function useNavigator() {
return redirectPath;
}

/**
* Converts a URL path or full URL string to a `URL` object.
*
* If the input string does not contain a protocol, it prepends the default `bundleId`
* and converts it into a complete URL. If a protocol exists, it directly converts the
* input into a `URL` object.
*
* @param pathOrUrl - The URL path or full URL string to be converted.
* @returns A `URL` object representing the complete URL.
*
* @example
* ```typescript
* const url1 = createAppURL('/path/to/resource');
* console.log(url1.toString()); // Outputs: app://path/to/resource
*
* const url2 = createAppURL('https://example.com/resource');
* console.log(url2.toString()); // Outputs: https://example.com/resource
* ```
*/
function createAppURL(pathOrUrl: string): URLParse<any> {
// Check if the input string contains a protocol using a regular expression.
const hasProtocol = /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(pathOrUrl);

// Convert the resulting string into a URL object and return it.
return urlParse(pathOrUrl, true);
}

/**
* Determines if a given route is associated with a bottom tab.
*
Expand Down Expand Up @@ -326,7 +296,7 @@ export function useNavigator() {
* open('/home');
*/
async function open(path: string, passProps = {}, options?: Options) {
const url = createAppURL(path);
const url = urlParse(path, true);
const matchedRoute = route.routes.find(it => {
return match(it.path)(url.pathname);
});
Expand Down Expand Up @@ -361,7 +331,7 @@ export function useNavigator() {
// Perform any associated action with the matched route
try {
if (matchedRoute.type === 'action') {
(matchedRoute as unknown as ActionRoute).action(
await (matchedRoute as unknown as ActionRoute).action(
url.href,
res ? res.params : {},
query,
Expand Down Expand Up @@ -494,8 +464,8 @@ export function useNavigator() {

return (
<ComponentIdContext.Provider value={componentId}>
<ModalContext.Provider value={{resolve, reject, data: passProps}}>
<Component />
<ModalContext.Provider value={{resolve, reject}}>
<Component {...passProps} />
</ModalContext.Provider>
</ComponentIdContext.Provider>
);
Expand Down Expand Up @@ -588,7 +558,7 @@ export function useLinking() {
if (!url) return;

try {
const {pathname, query} = urlParse(url, true);
const {pathname, query} = urlParse(url);

// Navigates to the parsed URL's pathname and search params
navigator.open(pathname + query);
Expand Down
3 changes: 0 additions & 3 deletions packages/app-router/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,4 @@ export type ModalData<T, U> = {
* @returns A function that rejects the modal.
*/
reject: (componentId: string) => () => void;

/** The data passed to the modal component. */
data: T;
};

0 comments on commit b207b3e

Please sign in to comment.