filterResources()

in public/assets/js/evm.js [70:114]


	filterResources(selectedFacets) {
		const { channels, resources, topics } = selectedFacets;

		return this.lunrResources.filter(resource => {
			if (channels.length && !channels.includes(resource.channel)) {
				if (!topics.length || (topics.length && resource.channel))
					return false;
			}

			if (channels.length && !channels.includes(resource.channel)) {
				if (!(topics.length && !resource.channel)) {
					return false;
				}
			}
			if (resources.length && !resources.includes(resource.resourceType)) {
				return false;
			}
			if (topics.length) {
				if (filterTopicsWithAnd) {
					// Match all selected topics against the resource's topics.
					for (const topic of topics) {
						if (!resource.topics?.includes(topic)) {
							return false;
						}
					}
				} else {
					// Get intersection of selected topics and this resource's
					// topics array. If there is any overlap, it's true.
					return topics.filter(topic => resource.topics?.includes(topic)).length > 0;
				}
			}

			return true;
		})
			.sort((a, b) => {
				// Sort in reverse date order
				if (a.datetime > b.datetime) {
					return -1;
				}
				if (a.datetime < b.datetime) {
					return 1;
				}
				return 0;
			});
	}