laws-africa / peachjam

Project Peach Jam
https://agp.africanlii.org
GNU General Public License v3.0
2 stars 0 forks source link

Search alerts / saved searches #2113

Open actlikewill opened 3 weeks ago

actlikewill commented 3 weeks ago

Users should be able to save some of their commonly repeated searches and be able to perform the same search with a single click. This feature will be most useful if it is quick and easliy accessible. While searching, users can be prompted to save a search in a non-intrusive manner, and still while searching, users can be prompted to bring up a saved search. Users should be able to view and remove previously saved searches.

Proposal

UX

Search page

When a user performs a search we show a "Subscribe" button in a box above the search results prompting them to subscribe to alerts for this search when new content is added.

If the user clicks on the button:

Search alerts page Users should be able to access their search alerts through a "Search Alerts" listing page. The page will display saved searches in a list view, sorted by date, showing:

Implementation

Add a new SavedSearch model with the following fields:

    q = models.CharField(max_length=4098)  # The primary search term(s).
    filters = models.CharField(max_length=4098)  # string or parameters for any filters/criteria.
    note = models.TextField(null=True, blank=True)  # additional notes that user wants to add.
    n_search_results = models.IntegerField(default=0)  # Number of results returned when initially saved.
    user = models.ForeignKey(User, on_delete=models.CASCADE)  # Link to the user who saved the search.
    date = models.DateField(auto_now_add=True)  # Automatically set the date when a search is saved.

Search results page

Saved searches page

Create a dedicated page with a simple list view for saved searches, displaying:

Save Search API Endpoint

Add a drf API endpoint to handle saving searches with relevant data (POST request): It should accept the search term, filter_parameters, note, user, and number of results.

longhotsummer commented 6 days ago

New pages and URLs

Search page

When a search is run, the Vue search app puts the search alert box into the page and uses HTMX (ajax?) to load the content of the box. This allows the server to check if a search alert for this search already exists.

If the user is not logged in, that html has a normal bootstrap modal with the login prompt, no special HTMX or JS needed.

If the user is logged in, and they have not saved this search, the button is part of a form which POSTs to a new endpoint that is submitted with HTMX and the box is updated with the text for a newly created saved search alert.

If the user is logged in and they have saved this search before, the box has an Unsubscribe experience that deletes the saved search.

Search alerts page

The search alert listing page also doubles as a detail page. It is part of the user profile page.

A search alert can be deleted by posting to the same deletion endpoint as above.

Clicking on a search alert opens the search page with all the details filled in.