lehoff

lehoff

Hi,

I am trying the help a local restaurant by putting up a simple website for ordering take-away.

I want to leverage LiveView to show the current order items on the right hand side.

I need to have a cookie based solution that preserves the order items when clicking on links (sub-menus for starters, mains, desserts, etc).
So far I have not been able to make it work and I have not been able to find any solutions/hints online.
I have tried using the _csrf_token, but it is not always present in the session.

I want to avoid forcing the customer to create a login - just have them state a mail/cell number so that the restaurant can tell when their order is ready. Everything is paid for at pick-up, no online payment (I’m just doing this as a favour to the local restaurant, so not going to open that box of goodies).
I have found several authentication related solutions for LiveView, but that is not the use case I’m after.

As far as I can tell it would be possible to control this better using straight Phoenix as the problem is related to the use of websockets in LiveView. I just fancy the idea of a live update of the current order in the style of LiveView. If it is impossible I will just revert to “plain” Phoenix, but that feels like an unnecessary defeat.

I am not an expert in Phoenix (LiveView) so please forgive me for my ignorance.
I hope that I have explained the problem well enough.

Cheers,
Torben

Showing Posts 1 to 6

dnsbty

dnsbty

Because the LiveView isn’t reloading the page, it isn’t really possible to set cookies server side.

Your best bet would be to either use JavaScript to set the cookie client side or to use AJAX to make it work similar to the solution outlined here:

mindok

mindok

Hi Torben,

There’s a discussion here that may give you a few ideas:

Or, you could use javascript hooks as described here: Persistent session data in Phoenix LiveView – The Pug Automatic - it’s a bit more roundabout, particularly if you want to share session state between liveviews.

mindok

mindok

… mid-air collision!

wmnnd

wmnnd

@lehoff: If you give PhoenixLiveSession a try, let me know how it worked for you :slight_smile:

lehoff

lehoff OP

@wmnnd

We got it to work with PhoenixLiveViewSession and managed to cut it down to the bare minimals:

  • Add the dependency.
  • Simple do-nothing handling of {:live_session_updated, session} in handle_info:
def handle_info({:live_session_updated, session}, socket) do
    {:noreply, socket}
end
  • Use PhoenLiveSession.maybe_subscribe/2 in mount/3:
socket = assign(
  socket,
  dishes: DatabaseLogic.get_dishes
)
|> PhoenixLiveSession.maybe_subscribe(session)

We have used for a long time now and it just works™.

wmnnd

wmnnd

Awesome :grinning:

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews