Commit e5cf5320 authored by greg@1m's avatar greg@1m
Browse files

search word api working in frontend

parent 1cb8c51b
......@@ -276,6 +276,13 @@ export const App = () => {
//@ts-ignore
window.api = api
useEffect(() => {
api.search.word("#[^ #]+", '/test_obsi/nodal_ex', res => {
console.log(3333, res);
})
}, [])
return (//jsx
<div className={CssApp2(mobileView, api.userSettings.refresh.css.get)} >
<div className={` ${deviceType() === 'mobile' ? `mobile-view-${mobileView}` : ''}`}>
......
......@@ -12,7 +12,7 @@ import { iFileApi, useFileApi } from './file.api.hook';
import { iFilesApi, useFilesApi } from './files.api.hook';
import { iFoldersApi, useFoldersApi } from './folders.api.hook';
import { iNoteHistoryApi } from './history.api.hook';
import { iSearchUiApi, useSearchApi } from './search.hook.api';
import { iSearchApi, iSearchUiApi, useSearchApi } from './search.hook.api';
import { iStatusApi } from './status.api.hook';
import { iUploadApi, useUploadApi } from './upload.api.hook';
import { getFunctionParamNames } from '../../managers/functions.manager';
......@@ -45,6 +45,7 @@ export interface iClientApi {
userSettings: iUserSettingsApi
history: iNoteHistoryApi
note: iNoteApi
search: iSearchApi
ui: {
browser: iBrowserApi
windows: iWindowsApi
......@@ -166,6 +167,7 @@ export const useClientApi = (p: {
history: p.historyApi,
status: p.statusApi,
note: noteApi,
search: searchApi,
ui: {
browser: browserApi,
windows: p.windowsApi,
......
import React, { useEffect, useRef, useState } from 'react';
import { iAppView, iFile } from '../../../../shared/types.shared';
import { iAppView, iFile, iSearchWordRes } from '../../../../shared/types.shared';
import { clientSocket2 } from '../../managers/sockets/socket.manager';
import { getLoginToken } from '../app/loginToken.hook';
import { genIdReq, getClientApi2, iApiEventBus } from './api.hook';
......@@ -9,10 +9,15 @@ import { iStatusApi } from './status.api.hook';
//
// INTERFACES
//
// MAIN
export interface iSearchApi {
files: iSearchFilesApi
word: (word: string, folder: string, cb: (res: iSearchWordRes) => void) => void
ui: iSearchUiApi
}
// SUB
export interface iSearchFilesApi {
search: (term: string, cb: (nFiles: iFile[]) => void) => void
}
......@@ -37,6 +42,15 @@ export const useSearchApi = (p: {
//
const [searchTerm, setSearchTerm] = useState('')
//
// LISTEN TO SOCKET
//
useEffect(() => {
clientSocket2.on('getWordSearch', data => {
p.eventBus.notify(data.idReq, data.result)
})
}, [])
//
// FUNCTIONS
//
......@@ -64,6 +78,17 @@ export const useSearchApi = (p: {
search(term, cb, 'text')
}
const searchWord: iSearchApi['word'] = (word, folder, cb) => {
const idReq = genIdReq(`search-word-`);
console.log(`${h} searching WORD ${word}`);
// subscribe
p.eventBus.subscribe(idReq, (res: iSearchWordRes) => { cb(res) });
// start request
clientSocket2.emit('searchWord', { word, folder, token: getLoginToken(), idReq })
}
const searchFilesAndUpdateUi: iSearchApi['ui']['search'] = term => {
getClientApi2().then(api => {
api.ui.browser.files.set([])
......@@ -82,6 +107,7 @@ export const useSearchApi = (p: {
files: {
search: searchFiles
},
word: searchWord,
ui: {
search: searchFilesAndUpdateUi,
//status: { get: isSearching, set: setIsSearching },
......
import { processRawPathToFile } from "./file.search.manager";
import { iSearchWordRes } from "../../../../shared/types.shared";
import { searchWithRgGeneric } from "./search-ripgrep.manager";
// rg "#[^ #]+" "/Users/gregoirethiebault/desktop/your markdown notes/test_obsi/nodal_ex" --ignore-case --type md --multiline
export const searchWord = (p: {
term: string,
folder: string,
cb: (res: any) => void
cb: (res: iSearchWordRes) => void
}) => {
const objRes = {}
const objRes: iSearchWordRes = {}
searchWithRgGeneric({
term: p.term,
folder: p.folder,
debug: true,
// debug: true,
processRawLine: lineInfos => {
let l = lineInfos
if (!l.found || l.found === '') return
if (!objRes[l.file.path]) objRes[l.file.path] = {file: l.file, results:[]}
objRes[l.file.path].results.push(l.found)
// return res
if (!objRes[l.file.path]) objRes[l.file.path] = { file: l.file, results: [] }
objRes[l.file.path].results.push(l.found)
},
onSearchEnded: async () => {
p.cb(objRes)
}
})
}
......@@ -17,6 +17,7 @@ import { ServerSocketManager } from './managers/socket.manager'
import { log } from "./managers/log.manager";
import { debounceCleanHistoryFolder } from "./managers/history.manager";
import { getFolderPath } from "./managers/path.manager";
import { searchWord } from "./managers/search/word.search.manager";
const serverTaskId = { curr: -1 }
let globalDateFileIncrement = { id: 1, date: dateId(new Date()) }
......@@ -62,6 +63,16 @@ export const listenSocketEndpoints = (serverSocket2: ServerSocketManager<iApiDic
})
serverSocket2.on('searchWord', async data => {
searchWord({
term: data.word,
folder: data.folder,
cb: res => {
serverSocket2.emit('getWordSearch', { result: res, idReq: data.idReq })
}
})
})
serverSocket2.on('searchFor', async data => {
// see if need to restrict search to a folder
let termObj = analyzeTerm(data.term)
......
......@@ -4,11 +4,8 @@ import { getPlatform } from './managers/platform.manager';
import { sslConfig } from './ssl.manager';
import { isEnvDev } from './managers/path.manager';
import { fileLogClean, log } from './managers/log.manager';
import { cloneDeep } from 'lodash';
import { startSecuredStaticServer } from './managers/staticServer.manager';
import { searchWithRgGeneric, searchWithRipGrep } from './managers/search/search-ripgrep.manager';
import { regexs } from '../../shared/helpers/regexs.helper';
import { searchWord } from './managers/search/allOccurences.search.manager';
import { searchWord } from './managers/search/word.search.manager';
fileLogClean();
......@@ -56,12 +53,20 @@ server.listen(backConfig.port, function () {
})
searchWord({
term: "#[^ #]+",
folder: '/test_obsi/nodal_ex',
cb: res => {
console.log(333, res, 333);
}
})
// searchWord({
// term: "#[^ #]+",
// folder: '/test_obsi/nodal_ex',
// cb: res => {
// console.log(333, res, 333);
// }
// })
// searchWord({
// term: "marx",
// folder: '/test_obsi/nodal_ex',
// cb: res => {
// console.log(333, res, 333);
// }
// })
// GOAL IS HAVING
import { iAppView, iFile, iFileImage, iFilePreview, iFolder, iSetupCode, iSetupForm } from "./types.shared";
import { iAppView, iFile, iFileImage, iFilePreview, iFolder, iSearchWordRes, iSetupCode, iSetupForm } from "./types.shared";
export interface iApiDictionary {
......@@ -23,6 +23,10 @@ export interface iApiDictionary {
moveFolder: { initPath: string, endPath: string }
searchFor: { term: string, type: iAppView, idReq: string }
searchWord: { word: string, folder: string, idReq: string }
getWordSearch: { result: iSearchWordRes, idReq: string }
getUploadedFile: { name: string, path: string, idReq: string }
askFolderHierarchy: { folderPath: string }
......
export type iSearchWordRes = { [filePath: string]: { file: iFile, results: string[] } }
export type iFileNature = 'file' | 'folder'
export type iViewType = 'editor' | 'editor-with-map' | 'both' | 'preview'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment