Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up scaffolds for state changes and DM slots #94

Merged
merged 92 commits into from
Sep 23, 2024

Conversation

rtshkmr
Copy link
Member

@rtshkmr rtshkmr commented Aug 21, 2024

This PR establishes the pattern on how we may define individual user_modes that determine what's presented to the user.

there are the following things that can be slotted into:

  1. control panel -- which has its own components
  2. hoverune
    typically for quick actions that are context specific (e.g. quick drafts)
  3. action_bar
    for common actions like navigation through an ordered list
  4. content
    for determining what content is to be displayed. This shall be user_mode-agnostic for now

When switching user modes from A to B, the DM will be able to switch what actions the user can do based on what's defined in the %UserMode{}

rtshkmr and others added 30 commits July 29, 2024 21:14
note: because of this, the PR requires the deployment to use a fresh json file

this prepares for the info needed by media sessions

does some linting using the latest elixir-ls
Not sure why it doesn't display when using the emulator.
I think it's better if I test it on the deployed version directly, not
sure if the testing method is accurate.
Init functions don't have action handlers yet
@rtshkmr rtshkmr changed the title [WIP] Set up scaffolds for state changes and DM slots Set up scaffolds for state changes and DM slots Aug 26, 2024
@rtshkmr rtshkmr marked this pull request as ready for review August 26, 2024 05:49
Copy link
Member Author

@rtshkmr rtshkmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than for the action bar, there's a pattern to how to declare UI elements specific to the user_mode

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the main place we define user modes, which determines what the user sees and what the user can do within a mode.

NOTE: the keys here might change, and some of them are really just for example purposes.

What's more or less fixed is this style of defining what is rendered and letting it get handler by render functions later, or being slotted into function components and such.
The "slotting" pattern that these try to follow is the main fixed part.

@impl true
# TODO: as a stop-gap we're using functions from Hoverune, this needs to be changed and
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a temp note for now.

Change to Draft
</.button>
<%= for other_mode <- @mode.control_panel_modes do %>
<.control_panel_mode_button
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is to show what other modes can be shifted to from this mode. This is the flow on how one can shift from one major mode to another

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function components specific to what's defined in user components get defined here.

so if I were to add another type of button to the hoverrune, then I shall:

  1. update the user_mode definitions
  2. add either a custom rendering function (component) or add mod existing stuff

@@ -174,8 +172,15 @@ defmodule VyasaWeb.DisplayManager.DisplayLive do

defp change_mode(socket, curr, target)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so mode changes get handled here

@@ -25,6 +25,12 @@
<.live_component module={@mode.control_panel_component} id="control_panel" mode={@mode} />
</div>

<.live_component
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hoverune is now a live component which is the responsiblity of the DM directly.

This allows emitting events from the live_component and handling it directly by the parent liveview (DM)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all the old vyasa_web/source_live/* files

@@ -47,7 +47,7 @@ defmodule Vyasa.MixProject do
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 4.0"},
{:phoenix_live_reload, "~> 1.5", only: :dev},
{:phoenix_live_view, "~> 0.20.17"},
{:phoenix_live_view, github: "phoenixframework/phoenix_live_view", ref: "440fd04", override: true},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: to support the stickyness behaviour across browser history navigation (i.e. pressing back / fwd button), we had to bump live_view version to the most updated.

Warning

this means that managing the :live_admin dep ends up being manual

@rtshkmr rtshkmr force-pushed the feat/drafting-state-handling branch 2 times, most recently from a51ba19 to dbcebf7 Compare August 26, 2024 12:41
[Attempt] display topbar only if non-mobile

Not sure if the ua_parsing actually works correctly

Minor change
@rtshkmr rtshkmr force-pushed the feat/drafting-state-handling branch from cd223ee to 2caf3f5 Compare August 26, 2024 12:43
Now, we do a check using the family values and doing a regex.
I suspect we'd need to keep updating this if the parsing breaks in
thefuture. but should be good enough for now.

also the different versions of the ua_parser lib seem to be giving
different output
Primarily for quick drafts
on mobile,
1. the mediabridge will be hidden (animated away by right)
2. once done typing, it should be visible again

It corresponds to:
1. if phone keyboard is open, hide the media player,
else show it

so that more screen space is given for mobile devices
This should be the "interface" to judge what the DM displays.
time to toh for now
@rtshkmr
Copy link
Member Author

rtshkmr commented Aug 27, 2024

trim.0860DC37-2510-4684-AA85-86549E2947DD.MOV

ks0m1c_dharma and others added 2 commits August 27, 2024 14:46
Similar to the hoverune implementation, this action_bar.ex live_component also takes in an array of actions, which the user_mode defines and then renders buttons that trigger click events specific to the mode and action_name.

This allows the DM to be the one with the necessary handlers to act on these events.

******* 1. Bars are soft appearing / disappearing
This means that we don't mount / destroy nodes, simply hide and make them appear as and when we need.
This means that we need to make some things "equivalent" and work the same way as it does on MediaBridge and ActionBar.

Suppose there are nav buttons (the left and right stuff) which are generic.
They will DEFINITELY appear on the MediaBridge.
They may or may not appear on the ActionBar.

This means that any button click on the nav buttons on MediaBridge may just be relayed to a optionally present button on the actionbar, along with other buttons on the action bar.

******* 2. Maintain equivalence in UI buttons b/w action-bar and media bridge by relaying button clicks
This will Shim / Relay the nav button click from the media bridge to the corresponding action bar via hooks

Essentially, clicking the nav buttons on the mediabridge will relay to the nav buttons on the action bar, which is mode-specific
Here's some logs to show that the wire-up looks okay (have left the functions empty first).

%Vix.Vips.Image{ref: #Reference<0.3949460734.1140719640.214139>}
[debug] HANDLE EVENT "read::nav_back" in VyasaWeb.DisplayManager.DisplayLive
  Parameters: %{"value" => ""}
TRACE: TODO handle nav_event @ action-bar region: %{"event" => "nav_back", "mode" => "read"}
[debug] Replied in 430µs
TRACE: TODO handle nav_event @ action-bar region: %{"event" => "nav_fwd", "mode" => "read"}
[debug] HANDLE EVENT "read::nav_fwd" in VyasaWeb.DisplayManager.DisplayLive
  Parameters: %{"value" => ""}
[debug] Replied in 375µs
TRACE handle event for toggle_show_control_panel: false
[debug] HANDLE EVENT "toggle_show_control_panel" in VyasaWeb.DisplayManager.DisplayLive
  Component: VyasaWeb.ControlPanel
  Parameters: %{"value" => ""}
[debug] Replied in 342µs
[debug] HANDLE EVENT "change_mode" in VyasaWeb.DisplayManager.DisplayLive
  Parameters: %{"current_mode" => "read", "target_mode" => "draft", "value" => ""}
[debug] Replied in 162µs
[debug] HANDLE EVENT "draft::nav_fwd" in VyasaWeb.DisplayManager.DisplayLive
  Parameters: %{"value" => ""}
TRACE: TODO handle nav_event @ action-bar region: %{"event" => "nav_fwd", "mode" => "draft"}
[debug] Replied in 562µs
TRACE: TODO handle nav_event @ action-bar region: %{"event" => "nav_back", "mode" => "draft"}
[debug] HANDLE EVENT "draft::nav_back" in VyasaWeb.DisplayManager.DisplayLive
  Parameters: %{"value" => ""}
[debug] Replied in 573µs
iex(test@127.0.0.1)1>
Copy link
Member Author

@rtshkmr rtshkmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, the last pattern of slottable action bar has a v1 implementation.

It's fairly rough around the edges, for example, the different patterns could definitely be more standardised and cleaned up.

I shall only tackle what very trivial refactors I can see, else will leave it to subsequent PRs to do the consolidation / cleanup of patterns here.

Also, customary video showing the magic on mobile phone:

freecompress-RPReplay_Final1724747990.mp4

Comment on lines +17 to +25
animation: {
ripple: "ripple 0.6s linear",
},
keyframes: {
ripple: {
"0%": { transform: "scale(0)", opacity: "0.5" },
"100%": { transform: "scale(4)", opacity: "0" },
},
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was experimenting with ripple effect, it's not being used but shall just leave it here for future inspiration

label: "TRACE: TODO handle nav_event @ action-bar region"
)

# TODO: implement nav_event handlers from action bar
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this empty for now, this shall get wired up in a subsequent PR.


@impl true
def handle_event(
"draft" <> "::" <> event = _nav_event,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the use of id-based click events allow us to pattern match for particular modes

@rtshkmr rtshkmr requested a review from ks0m1c August 27, 2024 09:03
ks0m1c and others added 7 commits August 27, 2024 17:07
Signed-off-by: a/vivekbala <avivekbala@gmail.com>
Acked-by: ks0m1c_dharma <sakiyamuni@sams.ara>
Persisting Marks Interim PR
Just comitting this while I make some UI mods next to that.
The reason why a live_component works here is that I expect to use some
collapsible state.
Base automatically changed from ops/librarian to master September 23, 2024 14:51
@ks0m1c ks0m1c merged commit df554e2 into master Sep 23, 2024
@ks0m1c ks0m1c deleted the feat/drafting-state-handling branch September 23, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants