feat: Introduce multi-platform architecture for Electron and Web clients with shared UI components, Convex backend for messaging, and integrated search functionality.
Some checks failed
Build and Release / build-and-release (push) Has been cancelled
Some checks failed
Build and Release / build-and-release (push) Has been cancelled
This commit is contained in:
47
packages/shared/src/utils/searchUtils.js
Normal file
47
packages/shared/src/utils/searchUtils.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const FILTER_RE = /\b(from|has|mentions|before|after|in|pinned):(\S+)/gi;
|
||||
|
||||
export function parseFilters(rawQuery) {
|
||||
const filters = {};
|
||||
let textQuery = rawQuery;
|
||||
|
||||
let match;
|
||||
while ((match = FILTER_RE.exec(rawQuery)) !== null) {
|
||||
const key = match[1].toLowerCase();
|
||||
const val = match[2];
|
||||
switch (key) {
|
||||
case 'from': filters.senderName = val; break;
|
||||
case 'has':
|
||||
if (val === 'link') filters.hasLink = true;
|
||||
else if (val === 'file' || val === 'attachment') filters.hasFile = true;
|
||||
else if (val === 'image') filters.hasImage = true;
|
||||
else if (val === 'video') filters.hasVideo = true;
|
||||
else if (val === 'mention') filters.hasMention = true;
|
||||
break;
|
||||
case 'mentions': filters.hasMention = true; filters.mentionName = val; break;
|
||||
case 'before': filters.before = val; break;
|
||||
case 'after': filters.after = val; break;
|
||||
case 'in': filters.channelName = val; break;
|
||||
case 'pinned': filters.pinned = val === 'true' || val === 'yes'; break;
|
||||
}
|
||||
textQuery = textQuery.replace(match[0], '');
|
||||
}
|
||||
FILTER_RE.lastIndex = 0;
|
||||
|
||||
return { textQuery: textQuery.trim(), filters };
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if the user is mid-typing a filter token.
|
||||
* e.g. "hello from:par" → { prefix: 'from', partial: 'par' }
|
||||
* e.g. "from:" → { prefix: 'from', partial: '' }
|
||||
* Returns null if no active prefix is detected at the end of text.
|
||||
*/
|
||||
export function detectActivePrefix(text) {
|
||||
if (!text) return null;
|
||||
// Match a filter prefix at the end of the string, possibly with a partial value
|
||||
const m = text.match(/\b(from|in|has|mentions):(\S*)$/i);
|
||||
if (m) {
|
||||
return { prefix: m[1].toLowerCase(), partial: m[2].toLowerCase() };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user