Skip to content

Commit

Permalink
fix(search): don't fetch cozy-notes url until Suggestion is clicked
Browse files Browse the repository at this point in the history
waiting for cozy/cozy-bar#770
  • Loading branch information
trollepierre committed Aug 9, 2022
1 parent 53cda5d commit ef865d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SuggestionProvider extends React.Component {
title: result.name,
subtitle: result.path,
term: result.name,
onSelect: 'open:' + result.url,
onSelect: result.onSelect || 'open:' + result.url,
icon: result.icon
}))
},
Expand All @@ -64,11 +64,8 @@ class SuggestionProvider extends React.Component {

const normalizedFilesPrevious = files.filter(notOrphans)

const normalizedFiles = await Promise.all(
normalizedFilesPrevious.map(
async file =>
await makeNormalizedFile(client, folders, file, getIconUrl)
)
const normalizedFiles = normalizedFilesPrevious.map(file =>
makeNormalizedFile(client, folders, file, getIconUrl)
)

this.fuzzyPathSearch = new FuzzyPathSearch(normalizedFiles)
Expand Down
15 changes: 12 additions & 3 deletions src/drive/web/modules/services/components/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@ import { models } from 'cozy-client'

export const TYPE_DIRECTORY = 'directory'

export const makeNormalizedFile = async (client, folders, file, getIconUrl) => {
/**
*
* @param client
* @param folders
* @param file
* @param getIconUrl
* @returns {{path: (*|string), name, icon, id, url: string, onSelect: (function(): Promise<string>)}}
*/
export const makeNormalizedFile = (client, folders, file, getIconUrl) => {
const isDir = file.type === TYPE_DIRECTORY
const dirId = isDir ? file._id : file.dir_id
const urlToFolder = `${window.location.origin}/#/folder/${dirId}`

let path, url
let path, url, onSelect
if (isDir) {
path = file.path
url = urlToFolder
} else {
const parentDir = folders.find(folder => folder._id === file.dir_id)
path = parentDir && parentDir.path ? parentDir.path : ''
if (models.file.isNote(file)) {
url = await models.note.fetchURL(client, file)
onSelect = () => models.note.fetchURL(client, file)
} else {
url = `${urlToFolder}/file/${file._id}`
}
Expand All @@ -26,6 +34,7 @@ export const makeNormalizedFile = async (client, folders, file, getIconUrl) => {
name: file.name,
path,
url,
onSelect,
icon: getIconUrl(file)
}
}

0 comments on commit ef865d8

Please sign in to comment.