Improve routing, and move the action pwa action receiver

This commit is contained in:
Enrico Ros
2023-11-21 22:17:17 -08:00
parent 6ed8529d6a
commit 16916db247
6 changed files with 24 additions and 16 deletions
@@ -4,11 +4,12 @@ import { useRouter } from 'next/router';
import { Alert, Box, Button, Typography } from '@mui/joy'; import { Alert, Box, Button, Typography } from '@mui/joy';
import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import { setComposerStartupText } from '../src/apps/chat/components/composer/store-composer'; import { setComposerStartupText } from '../../src/apps/chat/components/composer/store-composer';
import { AppLayout } from '~/common/layout/AppLayout'; import { AppLayout } from '~/common/layout/AppLayout';
import { LogoProgress } from '~/common/components/LogoProgress'; import { LogoProgress } from '~/common/components/LogoProgress';
import { asValidURL } from '~/common/util/urlUtils'; import { asValidURL } from '~/common/util/urlUtils';
import { navigateToIndex } from '~/common/app.routes';
/** /**
@@ -28,13 +29,13 @@ function AppShareTarget() {
const [isDownloading, setIsDownloading] = React.useState(false); const [isDownloading, setIsDownloading] = React.useState(false);
// external state // external state
const { query, push: routerPush, replace: routerReplace } = useRouter(); const { query } = useRouter();
const queueComposerTextAndLaunchApp = React.useCallback((text: string) => { const queueComposerTextAndLaunchApp = React.useCallback((text: string) => {
setComposerStartupText(text); setComposerStartupText(text);
void routerReplace('/'); void navigateToIndex(true);
}, [routerReplace]); }, []);
// Detect the share Intent from the query // Detect the share Intent from the query
@@ -110,7 +111,7 @@ function AppShareTarget() {
</Alert> </Alert>
<Button <Button
variant='solid' color='danger' variant='solid' color='danger'
onClick={() => routerPush('/')} onClick={() => navigateToIndex()}
endDecorator={<ArrowBackIcon />} endDecorator={<ArrowBackIcon />}
sx={{ mt: 2 }} sx={{ mt: 2 }}
> >
@@ -130,7 +131,7 @@ function AppShareTarget() {
/** /**
* This page will be invoked on mobile when sharing Text/URLs/Files from other APPs * This page will be invoked on mobile when sharing Text/URLs/Files from other APPs
* Example URL: https://get.big-agi.com/launch?title=This+Title&text=https%3A%2F%2Fexample.com%2Fapp%2Fpath * Example URL: https://localhost:3000/link/share_target?title=This+Title&text=https%3A%2F%2Fexample.com%2Fapp%2Fpath
*/ */
export default function LaunchPage() { export default function LaunchPage() {
return ( return (
+1 -1
View File
@@ -25,7 +25,7 @@
} }
], ],
"share_target": { "share_target": {
"action": "/launch", "action": "/link/share_target",
"method": "GET", "method": "GET",
"enctype": "application/x-www-form-urlencoded", "enctype": "application/x-www-form-urlencoded",
"params": { "params": {
@@ -160,7 +160,7 @@ export function Composer(props: {
const remainingTokens = tokenLimit - directTokens - historyTokens - responseTokens; const remainingTokens = tokenLimit - directTokens - historyTokens - responseTokens;
// Effect: load initial text if queued up (e.g. by /launch) // Effect: load initial text if queued up (e.g. by /link/share_targe)
React.useEffect(() => { React.useEffect(() => {
if (startupText) { if (startupText) {
setStartupText(null); setStartupText(null);
+2 -2
View File
@@ -9,7 +9,7 @@ import { useChatLinkItems } from '~/modules/trade/store-module-trade';
import { Brand } from '~/common/app.config'; import { Brand } from '~/common/app.config';
import { Link } from '~/common/components/Link'; import { Link } from '~/common/components/Link';
import { closeLayoutDrawer } from '~/common/layout/store-applayout'; import { closeLayoutDrawer } from '~/common/layout/store-applayout';
import { getChatLinkRelativePath, getHomeLink } from '~/common/app.routes'; import { getChatLinkRelativePath, ROUTE_INDEX } from '~/common/app.routes';
/** /**
@@ -28,7 +28,7 @@ export function AppChatLinkDrawerItems() {
<MenuItem <MenuItem
onClick={closeLayoutDrawer} onClick={closeLayoutDrawer}
component={Link} href={getHomeLink()} noLinkStyle component={Link} href={ROUTE_INDEX} noLinkStyle
> >
<ListItemDecorator><ArrowBackIcon /></ListItemDecorator> <ListItemDecorator><ArrowBackIcon /></ListItemDecorator>
{Brand.Title.Base} {Brand.Title.Base}
+2 -2
View File
@@ -5,10 +5,10 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { Brand } from '~/common/app.config'; import { Brand } from '~/common/app.config';
import { Link } from '~/common/components/Link'; import { Link } from '~/common/components/Link';
import { ROUTE_INDEX } from '~/common/app.routes';
import { capitalizeFirstLetter } from '~/common/util/textUtils'; import { capitalizeFirstLetter } from '~/common/util/textUtils';
import { newsCallout, NewsItems } from './news.data'; import { newsCallout, NewsItems } from './news.data';
import { ROUTE_APP_CHAT } from '~/common/app.routes';
export function AppNews() { export function AppNews() {
@@ -46,7 +46,7 @@ export function AppNews() {
<Box> <Box>
<Button <Button
variant='solid' color='neutral' size='lg' variant='solid' color='neutral' size='lg'
component={Link} href={ROUTE_APP_CHAT} noLinkStyle component={Link} href={ROUTE_INDEX} noLinkStyle
endDecorator='✨' endDecorator='✨'
sx={{ minWidth: 200 }} sx={{ minWidth: 200 }}
> >
+11 -4
View File
@@ -6,14 +6,21 @@
import Router from 'next/router'; import Router from 'next/router';
export const ROUTE_APP_CHAT = '/'; export const ROUTE_INDEX = '/';
const APP_LINK_CHAT = '/link/chat/:linkId'; export const ROUTE_APP_CHAT = '/chat';
export const ROUTE_APP_LINK_CHAT = '/link/chat/:linkId';
export const ROUTE_APP_NEWS = '/news';
export const getHomeLink = () => ROUTE_APP_CHAT; export const getIndexLink = () => ROUTE_INDEX;
export const getChatLinkRelativePath = (chatLinkId: string) => APP_LINK_CHAT.replace(':linkId', chatLinkId); export const getChatLinkRelativePath = (chatLinkId: string) => ROUTE_APP_LINK_CHAT.replace(':linkId', chatLinkId);
const navigateFn = (path: string) => (replace?: boolean): Promise<boolean> =>
Router[replace ? 'replace' : 'push'](path);
export const navigateToIndex = navigateFn(ROUTE_INDEX);
export const navigateToChat = async () => await Router.push(ROUTE_APP_CHAT); export const navigateToChat = async () => await Router.push(ROUTE_APP_CHAT);
export const navigateToNews = navigateFn(ROUTE_APP_NEWS);
export const navigateBack = Router.back; export const navigateBack = Router.back;