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
9 changes: 6 additions & 3 deletions apps/sim/app/o/[organizationId]/links/search-params.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { createSerializer, parseAsString } from 'nuqs/server'
import { SIM_LINK_SORTS } from '@/lib/sim-links/validation'
import { truncateAtCodePoint } from '@sim/utils/string'
import { createParser, createSerializer, parseAsString } from 'nuqs/server'
import { SIM_LINK_SEARCH_MAX_LENGTH, SIM_LINK_SORTS } from '@/lib/sim-links/validation'
import { createSortParams } from '@/lib/url-state'

const boundedSearch = (value: string) => truncateAtCodePoint(value, SIM_LINK_SEARCH_MAX_LENGTH, '')

/**
* `create` opens the new-link editor, prefilled with its value as the name. `search` filters by
* name, destination, or description.
*/
export const simLinksParsers = {
create: parseAsString,
search: parseAsString.withDefault(''),
search: createParser({ parse: boundedSearch, serialize: boundedSearch }).withDefault(''),
} as const

export const serializeSimLinkView = createSerializer(simLinksParsers)
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/o/[organizationId]/links/sim-links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useQueryStates } from 'nuqs'
import type { SimLink } from '@/lib/api/contracts/sim-links'
import { useDeploymentShape } from '@/lib/core/config/deployment-shape'
import { simLinkPath, simLinkUrl } from '@/lib/navigation/paths'
import { toSimLinkName } from '@/lib/sim-links/validation'
import { SIM_LINK_SEARCH_MAX_LENGTH, toSimLinkName } from '@/lib/sim-links/validation'
import { SEARCH_DEBOUNCE_MS } from '@/lib/url-state'
import {
INSTALL_EXTENSION_ACTION,
Expand Down Expand Up @@ -132,6 +132,7 @@ export function SimLinks({ organizationId }: SimLinksProps) {

const searchConfig: SearchConfig = {
value: search,
maxLength: SIM_LINK_SEARCH_MAX_LENGTH,
onChange: setSearch,
onClearAll: () => setSearch(''),
placeholder: SIM_LINKS_SEARCH_PLACEHOLDER,
Expand Down
8 changes: 2 additions & 6 deletions apps/sim/app/sim/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import {
type SimLinkResolution,
suggestSimLinks,
} from '@/lib/sim-links/application/use-cases'
import {
parseTypedSimLink,
SIM_LINK_SEARCH_MAX_LENGTH,
simLinkNameSchema,
} from '@/lib/sim-links/validation'
import { parseTypedSimLink, simLinkNameSchema } from '@/lib/sim-links/validation'
import { buildAuthCrossLink } from '@/app/(auth)/auth-redirect'
import { LogoShell } from '@/app/(landing)/components/logo-shell'
import { serializeSimLinkView } from '@/app/o/[organizationId]/links/search-params'
Expand Down Expand Up @@ -108,7 +104,7 @@ export default async function SimLinkPage({ params, searchParams }: SimLinkPageP
const validName = simLinkNameSchema.safeParse(name).success
// A name can't hold a space, so `sim card prices` is someone looking for a link, not naming one.
if (result.kind === 'not_found' && /\s/.test(name)) {
redirect(serializeSimLinkView(library, { search: name.slice(0, SIM_LINK_SEARCH_MAX_LENGTH) }))
redirect(serializeSimLinkView(library, { search: name }))
}
const creatable = result.kind === 'not_found' && validName
const similar = creatable
Expand Down
Loading