Displaying the most recent queries retrieved from a search API

Our web application built on angular.js utilizes a REST search API to query users within the system.

The endpoint for searching users is:

search/user?q='abc'

Upon revisiting the web application, we aim to display the user's recent search results.

Questions to consider :

Can this functionality be achieved within Angular.js or does it require a separate backend API to retrieve and display recent searches? If a backend solution is needed, should the data be stored in a database with timestamps for retrieval?

Answer №1

In my perspective, it is essential to focus on client-side development and use the "storage" feature provided by web browsers. There are three main options available for this purpose (although there may be others that I have overlooked).

  1. Utilizing cookie storage
  2. Implementing session storage
  3. Leveraging local storage

To delve deeper into these three options, refer to the following answer:

However, one drawback of utilizing these techniques is that the user's search history may not be permanently saved. Therefore, if the user accesses your web application through a different platform (such as an Android mobile app), their previous searches may not be retrievable.

Answer №2

Short version: I've developed a library specifically designed to handle recent searches and their edge cases. Check out https://github.com/JonasBa/recent-searches#readme for instructions on how to use it.

While the examples provided are valid, they don't cover all possible scenarios when storing recent searches. Things like implementing expiration, ranking, or limits for LocalStorage space need to be considered. One major drawback of using LocalStorage is that it's limited to the browser and device where the searches originate from. For example, if you search on your desktop and then switch to your mobile device, recent searches won't sync between the two. The same applies to different domains since LocalStorage is specific to each domain.

When implementing recent searches, remember to consider factors such as:

Expiration: Old queries may become obsolete over time, so having a system in place to manage this is crucial.

Ranking: Prioritizing more recent or relevant searches can enhance the user experience, especially when dealing with similar queries.

Efficiently managing LocalStorage: Simply adding data to LocalStorage without proper organization can lead to performance issues as the storage grows. This can eventually impact your application's speed and usability.

The recent-searches library addresses these challenges and provides solutions to help you create efficient recent searches functionality quickly and effectively!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error in scrolling previews detected in Jssor horizontal template maker

I've been working with Jssor Slider Maker and I'm using the vertical preview template that features two columns on the left side and a maximized image on the right side. After pulling the code from the developers pack, it includes scripts, CSS an ...

Excluding form items that are disabled from a request in ReactJS

In my code, I am dealing with a Form section that contains multiple Collapse.Panel sub-sections. Interestingly, the Form.Item elements within collapsed panels are not included in the form values upon submission. However, I have noticed that certain InputNu ...

Attempting to bind an input parameter using NgStyle in Angular version 2 and above

Issue: I am in need of a single component (spacer) with a width of 100% and a customizable height that can be specified wherever it is used in the HTML (specifically in home.html for testing): number 1 <spacer height="'200px'"></spa ...

Responsive design in Android does not function as intended

My goal is to create a responsive design for my website, but I am encountering issues with importing the CSS files into the HTML. When I try to view the site in both the Windows version of Chrome and the Android version, all I see is a white screen. I am c ...

Bringing in two JavaScript files with identical names

Recently, I encountered a challenging situation. I am working with material-ui and nextjs, both of which have a module called Link that is essential for my project. import { Link } from '@material-ui/core'; However, this setup is causing compil ...

Request to api.upcitemdb.com endpoint encountering CORS issue

This code may seem simple, but for some reason, it's not working as expected. What I'm trying to achieve is to call the GET API at: I want to make this API call using either JavaScript or jQuery. I've attempted various approaches, but none ...

What is the process for executing a Node.js file using a JavaScript command?

Currently, I am in the process of developing an online game that doesn't require high-speed interaction, allowing for the utilization of a single json file. My familiarity with node.js is limited, as I am relatively new to it. In my exploration, I ca ...

Creating a default homepage across various HTML files using Google Apps Script and deploying it as a WebApp

Is there a way to set a default main page on multiple HTML and GS files in Google AppScript? I plan to publish it as a Web App. Have you attempted using the doGet function? ...

Pressing a button meant to transfer text from a textarea results in the typed content failing to show up

Having trouble with a custom text area called a math field. I'm currently interning on a project to build a math search engine, where users can input plain text and LaTeX equations into a query bar. The issue I'm facing is that sometimes when th ...

Different time parameter for setting a timeout in Javascript

I am struggling to create a slideshow with varying time intervals for each image. My knowledge of Javascript is limited, and I have been working on resolving this issue for quite some time. /* function ShowEffect(element){ new Effect.Appear(element, ...

Having trouble with ReactJS updating the state in the correct format using moment?

In my ReactJS project, I am using a datepicker feature. However, I have encountered an issue where the state is not being updated with the selected date value after formatting it using moment.js. const [selectedDates, setSelectedDates] = useState([]) ...

Using typecasting method to extract value from a JSON object

Struggling with a JavaScript and JSON issue. There's a function that includes a JSON object: blah=function(i){ var hash= ({ "foo" : "bar", "eggs":"bacon", "sausage":"maple syrup" }); var j=eval(hash); // Convert to Object console.log(j.toSou ...

What is the best way to remove a specific item from a list of maps in DynamoDB based on a particular attribute value within the

Below is an example of a list I have: { "favorites": [ { "createdAt": 1448998673852, "entityId": "558da3de395b1aee2d6b7d2b", "type": "media" }, { "createdAt": 1448998789252, "entityId": "558da3de395b1aee2d6b7d83 ...

What does the HTML and JS code look like when using Next.Js?

Here's an illustration of the desired result: codepen.io/j0be/pen/jWGVvV How can I implement this HTML and JS in Next.js? I am looking to customize this code using TypeScript and SCSS in Next.js. However, I am unsure about how to convert the HTML an ...

Express (generator) is failing to load custom scripts located in the public folder

I'm new to node and express and I'm facing a problem. I want to load a custom script.js from the public folder, but it's not loading. There are no errors in the console or anything in the network tab. When I try to access the URL localhost:3 ...

trigger a label click when a button is clicked

I am in need of assistance with simulating a label click when a button is clicked. I attempted to make the label the same size as the button so that when the button is clicked, it would check my checkbox. I then tried using JavaScript to simulate the label ...

Animating jQuery to adjust height based on a percentage

My animation using percentage is not working as expected. It expands to the whole height instantly instead of smoothly transitioning to 100%. Here is my CSS code: #block-views{ overflow:hidden; height:20px; } This is my HTML code: <div id="block-view ...

Can we determine if a user's operating system has disabled animations?

In my frontend project with React, I am incorporating an animation within a component. However, I want to cater to users who have disabled animations in their settings by replacing the animated content with a static image. Is there a method to detect if ...

Show the subscription response data in Angular

When utilizing the code snippets below from two different components, I am able to receive a valid response value from the subscriber. dataService.ts fetchFormData(){ return this.http.get('http://localhost:48116/RecuruitmentService.asmx/addRoleTest ...

Uploading Boolean Values from Switch Input (React/Typescript)

I'm facing an issue while trying to post the state value of a switch input toggle control. Whenever I use the submitRecommendation() function through a button click, I encounter a JSON parse error: Cannot deserialize instance of `boolean` out of START ...