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

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews