frigate icon indicating copy to clipboard operation
frigate copied to clipboard

Added support to auto select last opened video camera on settings page using global state context provider

Open immkg opened this issue 1 year ago • 3 comments

Linked Issue: https://github.com/blakeblackshear/frigate/issues/12904

Problem

Opening setting page does not track the last selected camera and defaults to first camera

Screencast from 18-08-24 05:58:13 PM IST.webm

Solution

  1. Using a global state context provider to share common state across components
  2. Setting up the lastSelectedCamera from the Live View
  3. Using the lastSelectedCamera to initialize the selection

Screencast from 18-08-24 06:47:48 PM IST.webm

Test Outcome

Screencast from 18-08-24 06:46:00 PM IST.webm

immkg avatar Aug 18 '24 13:08 immkg

Deploy Preview for frigate-docs canceled.

Name Link
Latest commit 7a16424ae819b86f0c64394857d447b33bce7aa8
Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/66c1f6cde2d47200086a1282

netlify[bot] avatar Aug 18 '24 13:08 netlify[bot]

I don't think we want to use a context provider for this, especially when it only fits this specific instance. There are other ways that we could implement defaulting to camera settings when opening settings and a camera is selected.

For example, we could utilize a query arg on the settings page to select a different camera

NickM-27 avatar Aug 18 '24 13:08 NickM-27

it might also make sense to just have a separate settings button in the live view, I am not sure it is intuitive that pressing Settings takes you to different places based on where you are in the UI

NickM-27 avatar Aug 18 '24 13:08 NickM-27

Right we can use the alternative approach for this solution only. I made the choice of context provider to avoid localized solution of passing parameters from specific view.

immkg avatar Aug 18 '24 14:08 immkg

let's see what @hawkeye217 thinks

NickM-27 avatar Aug 18 '24 14:08 NickM-27

I'd agree with @NickM-27, I don't think a context provider is the correct solution here and that we need to be targeting a specific situation (camera automatically selected in Settings only after immediately viewing another camera in Live mode) rather than a global approach. As it is written right now, your code would bring up the wrong camera if I looked at camera1's live view, then navigated to the review pane, looked at some review items on camera2, and then navigated to Settings potentially a long while later.

hawkeye217 avatar Aug 18 '24 16:08 hawkeye217

Yes currently with the setup it only tracks the last camera opened in live view and does not track the last camera outside of live view.

if we want to only camera automatically selected in Settings only after immediately viewing another camera in Live mode then as @NickM-27 proposed we can go look into an separate settings button from the live view by passing an query and not use the global context.

But if do want to select the last view camera from other view's apart from the live view then we can set them using the global context as well.

immkg avatar Aug 18 '24 19:08 immkg

I don't think another button in Live view is the direction we want to go in. This is more of a convenience feature for users, so if there's no simple way to accomplish it in the ways we've already discussed then it likely isn't something worth including. The other devs may have a different opinion, though.

hawkeye217 avatar Aug 18 '24 19:08 hawkeye217

I think for now, there are a lot of changes expected in the upcoming frigate versions related to settings. More things will be moved into the settings UI, some things will likely be combined, the camera switching logic may change as well, so for now it would IMO be best to leave this alone and it can be revisited in the future

NickM-27 avatar Aug 18 '24 20:08 NickM-27

Sure, I am closing the PR.

immkg avatar Aug 18 '24 20:08 immkg