mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-10-18 06:03:22 +00:00
proper descending order sort in idb, filter.search
This commit is contained in:
parent
2755f09f59
commit
26050c20b8
@ -98,7 +98,7 @@ const Main = () => {
|
||||
<Search path="/search" focus={true} />
|
||||
<KeyConverter path="/key" />
|
||||
<Global path="/global" />
|
||||
<SearchFeed path="/search/:keyword" />
|
||||
<SearchFeed path="/search/:query" />
|
||||
<Login path="/login" fullScreen={true} />
|
||||
<Notifications path="/notifications" />
|
||||
<Chat path="/chat/:id?" />
|
||||
|
@ -1,7 +1,6 @@
|
||||
import loki from 'lokijs';
|
||||
import { Event } from 'nostr-tools';
|
||||
import { Event, Filter } from 'nostr-tools';
|
||||
|
||||
import Filter from '@/nostr/Filter';
|
||||
import { ID, STR } from '@/utils/UniqueIds';
|
||||
|
||||
export class EventDB {
|
||||
@ -98,7 +97,7 @@ export class EventDB {
|
||||
.chain()
|
||||
.find(query)
|
||||
.where((e: Event) => {
|
||||
if (filter.keywords && !filter.keywords.some((keyword) => e.content?.includes(keyword))) {
|
||||
if (filter.search && !e.content?.includes(filter.search)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -1,6 +0,0 @@
|
||||
import { Filter as NostrToolsFilter } from 'nostr-tools';
|
||||
|
||||
type Filter = NostrToolsFilter & {
|
||||
keywords?: string[];
|
||||
};
|
||||
export default Filter;
|
@ -184,7 +184,7 @@ const IndexedDB = {
|
||||
query = query.limit(filter.limit);
|
||||
}
|
||||
// TODO test that the sort is actually working
|
||||
await query.sortBy('created_at').reverse().each(handleEvent);
|
||||
await query.sortBy('-created_at').each(handleEvent);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
import throttle from 'lodash/throttle';
|
||||
import { Event, matchFilter } from 'nostr-tools';
|
||||
import { Event, Filter, matchFilter } from 'nostr-tools';
|
||||
|
||||
import EventDB from '@/nostr/EventDB';
|
||||
import Filter from '@/nostr/Filter';
|
||||
import getRelayPool from '@/nostr/relayPool';
|
||||
|
||||
import Events from '../nostr/Events';
|
||||
@ -92,7 +91,7 @@ const PubSub = {
|
||||
|
||||
subscribeRelayPool(filter: Filter, sinceLastOpened: boolean, mergeSubscriptions: boolean) {
|
||||
let relays;
|
||||
if (filter.keywords) {
|
||||
if (filter.search) {
|
||||
relays = Array.from(Relays.searchRelays.keys());
|
||||
} else if (mergeSubscriptions || filter.authors?.length !== 1) {
|
||||
relays = Relays.enabledRelays();
|
||||
|
@ -66,7 +66,6 @@ const Relays = {
|
||||
filtersBySubscriptionName: new Map<string, string>(),
|
||||
subscribedEventTags: new Set<string>(),
|
||||
subscribedProfiles: new Set<string>(),
|
||||
subscribedKeywords: new Set<string>(), // seach keywords
|
||||
subscriptionsByName: new Map<string, Set<Sub>>(),
|
||||
newAuthors: new Set<string>(),
|
||||
DEFAULT_RELAYS,
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import throttle from 'lodash/throttle';
|
||||
import { Event } from 'nostr-tools';
|
||||
import { Event, Filter } from 'nostr-tools';
|
||||
|
||||
import EventDB from '@/nostr/EventDB.ts';
|
||||
import Filter from '@/nostr/Filter.ts';
|
||||
import PubSub from '@/nostr/PubSub.ts';
|
||||
|
||||
interface SubscribeOptions {
|
||||
|
@ -96,4 +96,4 @@ const Search = (props: any) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Search;
|
||||
export default memo(Search);
|
||||
|
@ -83,7 +83,7 @@ const View = ({ children, hideHeader = false, hideSideBar = false }) => {
|
||||
</div>
|
||||
<Show when={!hideSideBar}>
|
||||
<div className="flex-col hidden lg:flex lg:w-1/3">
|
||||
<Search focus={false} />
|
||||
<Search key="search" focus={false} />
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
|
@ -7,16 +7,16 @@ import View from '../View';
|
||||
|
||||
type Props = {
|
||||
path: string;
|
||||
keyword?: string;
|
||||
query?: string;
|
||||
};
|
||||
|
||||
const Search: React.FC<Props> = ({ keyword }) => {
|
||||
const Search: React.FC<Props> = ({ query }) => {
|
||||
const filterOptions = useMemo(() => {
|
||||
const filter = { kinds: [1], keywords: [keyword || ''] };
|
||||
const filter = { kinds: [1], search: query };
|
||||
|
||||
const filterFn = (event) => {
|
||||
// some relays don't support filtering by keyword
|
||||
return event.content.includes(keyword);
|
||||
return event.content.includes(query);
|
||||
};
|
||||
|
||||
return [
|
||||
@ -26,13 +26,13 @@ const Search: React.FC<Props> = ({ keyword }) => {
|
||||
filterFn,
|
||||
},
|
||||
];
|
||||
}, [keyword]);
|
||||
}, [query]);
|
||||
|
||||
return (
|
||||
<View>
|
||||
<div className="flex flex-row">
|
||||
<div className="flex flex-col w-full">
|
||||
<FeedComponent key={keyword} filterOptions={filterOptions} />
|
||||
<FeedComponent key={query} filterOptions={filterOptions} />
|
||||
</div>
|
||||
</div>
|
||||
</View>
|
||||
|
Loading…
Reference in New Issue
Block a user