Skip to content

Commit

Permalink
Avoid landing to selection page when searching
Browse files Browse the repository at this point in the history
  • Loading branch information
ayanamists committed Jul 17, 2024
1 parent 8ae957e commit a222860
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/omot-server/src/pages/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import 'instantsearch.css/themes/satellite.css';
import { InstantSearch, SearchBox, Highlight, InfiniteHits } from 'react-instantsearch';
import searchClient from '@/util/search';
import MainLayout from '@/layouts/MainLayout';
import { Box, Button, useMediaQuery, useTheme, } from '@mui/material';
import Link from 'next/link';
import { Box, Button, useMediaQuery, useTheme, Link } from '@mui/material';

const Hit = ({ hit }: {hit:any}) => {
const Hit = ({ hit }: {hit:any}) => {
const tweetUrl = hit.tweetUrl;
const splited = tweetUrl.split('/');
const userName = splited[splited.indexOf('status') - 1];
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const isiPad = useMediaQuery('(max-width: 1372px)');
const mw = isMobile ? '100%' : (isiPad ? '60vw' : '40vw');
const computedLink = `/user/${userName}/?showReply=${hit.repliesToOriginalId == null ? "false" : "true"}#tweet${hit.originalId}`;
const computedUserLink = `/user/${userName}/?userId=${hit.userId}`;
const computedLink = `/user/${userName}/?userId=${hit.userId}&showReply=${hit.repliesToOriginalId == null ? "false" : "true"}#tweet${hit.originalId}`;
return (<Box width={mw}>
<Highlight attribute="content" hit={hit} highlightedTagName="mark" />
<Box display={'flex'} sx={{
Expand All @@ -23,7 +23,7 @@ const Hit = ({ hit }: {hit:any}) => {
padding: '0.5em 0',
}}>
<Box>
From: <Link href={`/user/${userName}`} >{userName}</Link>
From: <Link href={computedUserLink} >{userName}</Link>
</Box>
<Button variant='contained' sx={{width:"50%"}} href={computedLink}>
GOTO
Expand Down
12 changes: 11 additions & 1 deletion packages/omot-server/src/pages/user/[name].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ function processOriginalId(originalId: string | string[] | undefined) {
}
}

function processUserId(userId: string | string[] | undefined) {
if (typeof userId === "string") {
return Number.parseInt(userId);
} else {
return undefined;
}
}

export const getServerSideProps = (async (context) => {
const userName = context.params?.name;
const _userId = processUserId(context.query.userId);
const showReply = processShowReply(context.query.showReply);
const originalId = processOriginalId(context.query.originalId);
if (userName == null) {
Expand All @@ -64,7 +73,8 @@ export const getServerSideProps = (async (context) => {
},
}
},
...(originalId && { originalId })
...(originalId && { originalId }),
...(_userId && { id: _userId })
},
});
if (users.length === 0) {
Expand Down

0 comments on commit a222860

Please sign in to comment.