diff --git a/src/Packages.res b/src/Packages.res index 3b2aa851c..fac378a3d 100644 --- a/src/Packages.res +++ b/src/Packages.res @@ -23,21 +23,27 @@ type npmPackage = { description: string, repositoryHref: Js.Null.t, npmHref: string, + searchScore: float, + maintenanceScore: float, } +// These are packages that we do not want to filter out when loading searching from NPM. +let packageAllowList: array = [] + module Resource = { - type t = Npm(npmPackage) | Url(urlResource) + type t = Npm(npmPackage) | Url(urlResource) | Outdated(npmPackage) let getId = (res: t) => { switch res { | Npm({name}) + | Outdated({name}) | Url({name}) => name } } let shouldFilter = (res: t) => { switch res { - | Npm(pkg) => + | Npm(pkg) | Outdated(pkg) => if pkg.name->Js.String2.startsWith("@elm-react") { true } else if pkg.name->Js.String2.startsWith("bs-") { @@ -71,7 +77,7 @@ module Resource = { let isOfficial = (res: t) => { switch res { - | Npm(pkg) => + | Npm(pkg) | Outdated(pkg) => pkg.name === "rescript" || pkg.name->Js.String2.startsWith("@rescript/") || pkg.name === "gentype" @@ -94,7 +100,9 @@ module Resource = { let fuser = Fuse.make(packages, fuseOpts) - fuser->Fuse.search(pattern) + fuser + ->Fuse.search(pattern) + ->Js.Array2.sortInPlaceWith((a, b) => a["item"].searchScore > b["item"].searchScore ? -1 : 1) } let applyUrlResourceSearch = (urls: array, pattern: string): array< @@ -116,20 +124,26 @@ module Resource = { } let applySearch = (resources: array, pattern: string): array => { - let (allNpms, allUrls) = Belt.Array.reduce(resources, ([], []), (acc, next) => { - let (npms, resources) = acc + let (allNpms, allUrls, allOutDated) = Belt.Array.reduce(resources, ([], [], []), ( + acc, + next, + ) => { + let (npms, resources, outdated) = acc switch next { | Npm(pkg) => Js.Array2.push(npms, pkg)->ignore | Url(res) => Js.Array2.push(resources, res)->ignore + | Outdated(pkg) => Js.Array2.push(outdated, pkg)->ignore } - (npms, resources) + (npms, resources, outdated) }) let filteredNpm = applyNpmSearch(allNpms, pattern)->Belt.Array.map(m => Npm(m["item"])) let filteredUrls = applyUrlResourceSearch(allUrls, pattern)->Belt.Array.map(m => Url(m["item"])) + let filteredOutdated = + applyNpmSearch(allOutDated, pattern)->Belt.Array.map(m => Outdated(m["item"])) - Belt.Array.concat(filteredNpm, filteredUrls) + Belt.Array.concatMany([filteredNpm, filteredUrls, filteredOutdated]) } } @@ -137,14 +151,14 @@ module Card = { @react.component let make = (~value: Resource.t, ~onKeywordSelect: option unit>=?) => { let icon = switch value { - | Npm(_) => + | Npm(_) | Outdated(_) => | Url(_) => } let linkBox = switch value { - | Npm(pkg) => + | Npm(pkg) | Outdated(pkg) => let repositoryHref = Js.Null.toOption(pkg.repositoryHref) let repoEl = switch repositoryHref { | Some(href) => @@ -169,12 +183,14 @@ module Card = { } let titleHref = switch value { - | Npm(pkg) => pkg.repositoryHref->Js.Null.toOption->Belt.Option.getWithDefault(pkg.npmHref) + | Npm(pkg) | Outdated(pkg) => + pkg.repositoryHref->Js.Null.toOption->Belt.Option.getWithDefault(pkg.npmHref) | Url(res) => res.urlHref } let (title, description, keywords) = switch value { | Npm({name, description, keywords}) + | Outdated({name, description, keywords}) | Url({name, description, keywords}) => (name, description, keywords) } @@ -238,6 +254,7 @@ module Filter = { includeCommunity: bool, includeNpm: bool, includeUrlResource: bool, + includeOutdated: bool, } } @@ -263,7 +280,7 @@ module InfoSidebar = {