Skip to content

Commit

Permalink
Further cleanup of SearchableIndex migration shim
Browse files Browse the repository at this point in the history
  • Loading branch information
judeallred committed Oct 21, 2023
1 parent 91ebb6a commit 5076895
Showing 1 changed file with 82 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { useEffect, useReducer, useRef } from "react";
import { useDispatch, useStore } from "react-redux";
import { Subject } from "rxjs";
import { useReducer } from "react";

import type { ResourceProject } from "../../../../features/project/types";

Expand All @@ -10,9 +8,9 @@ export const useSearchIndex = (): {
onChange: (term: string) => void;
searchTerm: string;
} => {
const searchTermSubjectRef = useRef(new Subject<string>());
const appDispatch = useDispatch();
const store = useStore();
// const searchTermSubjectRef = useRef(new Subject<string>());
// const appDispatch = useDispatch();
// const store = useStore();

const [{ loading, results, searchTerm }, dispatch] = useReducer(
(
Expand Down Expand Up @@ -44,86 +42,84 @@ export const useSearchIndex = (): {
{ loading: true, results: [], searchTerm: "" }
);

useEffect(() => {
// migration shim
return;

// const search = async (searchTerm: string, signal: AbortSignal) => {
// try {
// dispatch({ type: "BEGIN_SEARCH" });

// const results = await searchResourceProjects(searchTerm, signal);

// // Search is triggered on page load - we don't want to track those as events
// if (searchTerm) {
// appDispatch(
// trackEvent({ action: "Index Search: Core", label: searchTerm })
// );
// }

// if (signal.aborted) {
// return;
// }

// dispatch({ type: "FINISHED_SEARCHING", payload: results });
// } catch (err) {
// if (err.name !== "AbortError") {
// console.error("Could not fetch resources", err);

// dispatch({ type: "ERROR" });
// }
// }
// };

// let controller: AbortController | null = null;

// const storeObs = fromStore(store);
// const subscription = combineLatest([
// merge(
// searchTermSubjectRef.current.pipe(skip(1), debounceTime(500)),
// searchTermSubjectRef.current.pipe(take(1)),
// projectChangeObservable(store).pipe(
// withLatestFrom(searchTermSubjectRef.current),
// map((pair) => pair[1] ?? "")
// ),
// storeObs.pipe(
// filter(selectProjectLoaded),
// map(selectLatestReleaseTag),
// distinctUntilChanged(),
// withLatestFrom(searchTermSubjectRef.current),
// map((pair) => pair[1] ?? "")
// )
// ),
// storeObs.pipe(
// filter(selectProjectLoaded),
// map(selectScope[Scope.save]),
// distinctUntilChanged()
// ),
// ])
// .pipe(debounceTime(0))
// .subscribe(([searchTerm, canSave]) => {
// controller?.abort();

// if (canSave) {
// controller = new AbortController();

// search(searchTerm, controller.signal).catch((err) => {
// if (err.name !== "AbortError") {
// console.error(err);
// }
// });
// }
// });

// return () => {
// controller?.abort();
// subscription.unsubscribe();
// };
}, [appDispatch, store]);

useEffect(() => {
searchTermSubjectRef.current.next(searchTerm);
}, [searchTerm]);
// migration shim
// useEffect(() => {
// const search = async (searchTerm: string, signal: AbortSignal) => {
// try {
// dispatch({ type: "BEGIN_SEARCH" });

// const results = await searchResourceProjects(searchTerm, signal);

// // Search is triggered on page load - we don't want to track those as events
// if (searchTerm) {
// appDispatch(
// trackEvent({ action: "Index Search: Core", label: searchTerm })
// );
// }

// if (signal.aborted) {
// return;
// }

// dispatch({ type: "FINISHED_SEARCHING", payload: results });
// } catch (err) {
// if (err.name !== "AbortError") {
// console.error("Could not fetch resources", err);

// dispatch({ type: "ERROR" });
// }
// }
// };

// let controller: AbortController | null = null;

// const storeObs = fromStore(store);
// const subscription = combineLatest([
// merge(
// searchTermSubjectRef.current.pipe(skip(1), debounceTime(500)),
// searchTermSubjectRef.current.pipe(take(1)),
// projectChangeObservable(store).pipe(
// withLatestFrom(searchTermSubjectRef.current),
// map((pair) => pair[1] ?? "")
// ),
// storeObs.pipe(
// filter(selectProjectLoaded),
// map(selectLatestReleaseTag),
// distinctUntilChanged(),
// withLatestFrom(searchTermSubjectRef.current),
// map((pair) => pair[1] ?? "")
// )
// ),
// storeObs.pipe(
// filter(selectProjectLoaded),
// map(selectScope[Scope.save]),
// distinctUntilChanged()
// ),
// ])
// .pipe(debounceTime(0))
// .subscribe(([searchTerm, canSave]) => {
// controller?.abort();

// if (canSave) {
// controller = new AbortController();

// search(searchTerm, controller.signal).catch((err) => {
// if (err.name !== "AbortError") {
// console.error(err);
// }
// });
// }
// });

// return () => {
// controller?.abort();
// subscription.unsubscribe();
// };
// }, [appDispatch, store]);

// useEffect(() => {
// searchTermSubjectRef.current.next(searchTerm);
// }, [searchTerm]);

return {
onChange: (searchTerm: string) =>
Expand Down

0 comments on commit 5076895

Please sign in to comment.