-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into left-nav-desktop
* origin/main: Adjust line height to not cut off emoji (#5496) Emoji in account list (#5497) Make the counter more rounded (#5083) add emoji prop to composer reply to text (#5495) Fix banner height in edit profile modal (#5494) Messages list - make avatars link to profile (#5484) Add back empty placeholder (#5489) Filter errors that get sent to Sentry (#5247) Add language filtering UI to search (#5459)
- Loading branch information
Showing
17 changed files
with
498 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {describe, expect, it} from '@jest/globals' | ||
|
||
import {parseSearchQuery} from '#/screens/Search/utils' | ||
|
||
describe(`parseSearchQuery`, () => { | ||
const tests = [ | ||
{ | ||
input: `bluesky`, | ||
output: {query: `bluesky`, params: {}}, | ||
}, | ||
{ | ||
input: `bluesky from:esb.lol`, | ||
output: {query: `bluesky`, params: {from: `esb.lol`}}, | ||
}, | ||
{ | ||
input: `bluesky "from:esb.lol"`, | ||
output: {query: `bluesky "from:esb.lol"`, params: {}}, | ||
}, | ||
{ | ||
input: `bluesky mentions:@esb.lol`, | ||
output: {query: `bluesky`, params: {mentions: `@esb.lol`}}, | ||
}, | ||
{ | ||
input: `bluesky since:2021-01-01:00:00:00`, | ||
output: {query: `bluesky`, params: {since: `2021-01-01:00:00:00`}}, | ||
}, | ||
{ | ||
input: `bluesky lang:"en"`, | ||
output: {query: `bluesky`, params: {lang: `en`}}, | ||
}, | ||
{ | ||
input: `bluesky "literal" lang:en "from:invalid"`, | ||
output: {query: `bluesky "literal" "from:invalid"`, params: {lang: `en`}}, | ||
}, | ||
] | ||
|
||
it.each(tests)( | ||
`$input -> $output.query $output.params`, | ||
({input, output}) => { | ||
expect(parseSearchQuery(input)).toEqual(output) | ||
}, | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export type Params = Record<string, string> | ||
|
||
export function parseSearchQuery(rawQuery: string) { | ||
let base = rawQuery | ||
const rawLiterals = rawQuery.match(/[^:\w\d]".+?"/gi) || [] | ||
|
||
// remove literals from base | ||
for (const literal of rawLiterals) { | ||
base = base.replace(literal.trim(), '') | ||
} | ||
|
||
// find remaining params in base | ||
const rawParams = base.match(/[a-z]+:[a-z-\.@\d:"]+/gi) || [] | ||
|
||
for (const param of rawParams) { | ||
base = base.replace(param, '') | ||
} | ||
|
||
base = base.trim() | ||
|
||
const params = rawParams.reduce((params, param) => { | ||
const [name, ...value] = param.split(/:/) | ||
params[name] = value.join(':').replace(/"/g, '') // dates can contain additional colons | ||
return params | ||
}, {} as Params) | ||
const literals = rawLiterals.map(l => String(l).trim()) | ||
|
||
return { | ||
query: [base, literals.join(' ')].filter(Boolean).join(' '), | ||
params, | ||
} | ||
} | ||
|
||
export function makeSearchQuery(query: string, params: Params) { | ||
return [ | ||
query, | ||
Object.entries(params) | ||
.map(([name, value]) => `${name}:${value}`) | ||
.join(' '), | ||
] | ||
.filter(Boolean) | ||
.join(' ') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.