The navigation system of Meteor using angular-ui-router

Hey, I'm facing an issue where when a user lands on a specific page, I need to run a check to see if there are any entries in a collection that are missing a certain attribute. If so, I want to redirect the user. I've outlined what I think the code should look like, but for some reason, I can't get the subscription to work in the routes.js file.

Here's a snippet from my routes.js:

.state('pendingVisits', {
    url: '/pendingVisits',
    templateUrl: ()=> {
      if (Meteor.isCordova) {
        return '/packages/visitry-mobile/client/visits/pending-visits/pending-visits.html';
      } else {
        return '/packages/visitry-browser/client/visits/pending-visits/pending-visits.html';
      }
    },
    controller: 'pendingVisitsCtrl as pendingVisits',
    resolve:{
      feedback: function($location){
        Meteor.subscribe('visits');
        var v = Visits.findOne({feedbackId});
        if(v){
          $location.url('/visits/'+v._id+'/feedback');
        }
      }
    }
});

I'm essentially aiming to replicate Uber's UI behavior, where if there is no feedback for the last event, the feedback page is displayed. Any assistance would be greatly appreciated. Feel free to ask for more code or details if needed.

Answer №1

I managed to come up with a solution using Tracker.autorun(). Here is the approach I implemented:

resolve:{
  feedback:function($location){
    const subscriptions = Meteor.subscribe('visits');
    Tracker.autorun(()=>{
      const isSubscriptionReady = subscriptions.ready();
      var visitNeedingFeedback = Visits.findOne({feedbackId:null})
      if(isSubscriptionReady && visitNeedingFeedback){
        console.log("Redirecting to feedbacks page");
        $location.url('/feedback/'+ visitNeedingFeedback._id);
      }else{
        console.log(`Visits data is ${isSubscriptionReady ? 'ready' : 'not ready'}`)
      }
    })
  }
}

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

Are you experiencing issues with incorrect JSON formatting?

At times, I have observed individuals sending JSON data to a server using the following code: $.ajax({ url: ... contentType: "application/json; charset=utf-8", dataType: "json", data: { 'page': '100AAAAAf00' }, responseType: "json", su ...

A recent challenge encountered with JavaScript involving incrementation

After successfully resolving my previous issue with the assistance of another user, I'm now encountering a new problem related to the following code snippet: const faker = require('faker'); const userList = require('./users.json') ...

Loop Through Array Elements Generated from a State in JavaScript

I'm struggling with a scenario where I have a list of items containing nested data stored in my component's state. My aim is to display these items on the screen and provide functionality for users to navigate through them using next and previous ...

Implementing external pagination and data export in a UI-grid

Currently, I am utilizing ui-grid with external pagination to showcase my data. A problem has arisen where I can only export the data that is currently being viewed. In order to meet my requirements, it is necessary for me to be able to export ALL the data ...

Encountering error while attempting POST request in POSTMAN - "Unable to modify in restricted editor."

I'm facing a bit of a dilemma here. I can't seem to figure out how to make my editor in Postman stop being read-only. Can anyone lend a hand? Whenever I try to send a Post Request, my editor just won't cooperate and stays in Read-Only mode. ...

Incorporating useState into React Native navigation screens to dynamically update FlatList items

I'm working on implementing react-navigation to pass and update useState between screens in order to render a flatlist. The issue I am facing is that the flatlist updates correctly when I navigate back to the previous screen and then return to the com ...

Malfunctioning JavaScript timepiece

I am currently experimenting with using Raphael to create a unique clock feature on my website. My goal is to animate the seconds hand to mimic the movement of a traditional clock. Below is the code snippet I have implemented: window.onload = function( ...

pg-promise received an error due to an incorrect parameter being passed in for options

I have been working on transitioning my files from utilizing the pg package to the pg-promise package. Initially, everything was functioning correctly with the original pg solution I had in place. However, upon switching to pg-promise and referencing the d ...

Is there a consistent order required when calling React Hooks in each component render?

After implementing keyboard key or button navigation in a list of items, I encountered errors during the build phase that do not occur locally. The specific errors are as follows: Error: React Hook "useRef" is called conditionally. React Hooks m ...

An error handling event for XHTML compliance, similar to the HTML onerror event, is designed to address the issue of

Below is a piece of code that handles hiding the placeholder (imagecontent) for dynamically populated empty images and their captions: <head> <script type="text/javascript"> function hideEmptyImage() { document.getElementById(&q ...

If the element does not already exist, use jQuery to append it; otherwise, replace the existing element

Check out this snippet of code: const $element = $("#something").find(".test"); if (!$element.length) { $("#something").append('<div class="test">somecontent</div>'); } else { $element.replaceWith('<div class="test"&g ...

When toggling between light and dark themes using the useMediaQuery hook, the Material-ui styling is being overridden

While working with next.js and material-ui, I encountered an issue where the theme would change based on user preference. However, when switching to light mode, the JSS Styles that I had set were being overwritten. This problem only seemed to occur in ligh ...

Locate the unique symbol within an array

I am facing a challenge with validating user input in an input box where alphanumeric values are allowed along with certain special characters. I need to display an error message if the user enters a special character that is not supported by my applicatio ...

The call function in Tween.js fails to execute after adding an EventListener

I encountered an issue while using tween.0.6.2. The following code snippet (borrowed from the tween.js Getting Started page and slightly simplified) works perfectly: createjs.Tween.get(circle) .to({x: 400}, 1000, createjs.Ease.getPowInOut ...

Guide to utilizing jQuery for random toggling of classes

My objective is to create a mouseover effect on a box that changes its color randomly. Currently, I have managed to achieve this by toggling one class (e.g. $("#evtTarget").toggleClass(highlighted-2);). However, I am now attempting to select a random class ...

Refresh the cells in the UI ListView

Currently, I am working on implementing a long scrollable list of names for a PhoneGap (iOS) app using Onsen UI. To achieve this, I found a dynamic list view module that is compatible with this UI at the following link: Although I have managed to make it ...

Synchronize two slideshows in a cycle with timed delays between each cycle

Is there a way to add a sequential delay between slideshows in the synchronized slide show example from cycle2 API? For example, having each div.cycle-slideshow start at 5s intervals (5s, 10s, 15s, 20s...). The cycle would then repeat with the first div st ...

Ways to trigger an alert based on a MySQL query output?

I've been searching all day but can't seem to figure it out. Basically, I have an HTML page with a jQuery function that sends data to a PHP file to fetch information from a database. Retrieving the data to the HTML page is working fine. Now, wh ...

Chrome debugging tool does not refresh page source

This issue has been lingering for quite some time and despite similar questions, I have not come across a satisfactory solution. The problem lies in the fact that the SOURCE used to step through the code does not refresh with every page load. Disabling the ...

Attempting to send a request from the front-end to the back-end is resulting in a 404 endpoint error

I encountered an issue while sending a post request from the front end to the backend. The error message I received was: " Error: Request failed with status code 404 " " Had Issues POSTing to the backend, endpoint " My main concern is ...