72 lines
2.8 kB
1
# defmodule BlogWeb.MuensterLive do
2
# use BlogWeb, :live_view
3
# import BlogWeb.CoreComponents
4
# require Logger
5
#
6
# @max_posts 500
7
#
8
# def mount(_params, _session, socket) do
9
# if connected?(socket) do
10
# Phoenix.PubSub.subscribe(Blog.PubSub, "muenster_posts")
11
# end
12
# import Ecto.Query
13
# # skeets no longer just contain muenster...
14
# posts = Blog.Repo.all(
15
# from s in Blog.Social.Skeet,
16
# where: ilike(s.skeet, "%muenster%"),
17
# order_by: [desc: s.inserted_at],
18
# limit: 3,
19
# select: %{text: s.skeet, timestamp: s.inserted_at}
20
# )
21
# # get the most recent ten muenster skeets from the database
22
# {:ok, assign(socket,
23
# posts: posts,
24
# total_count: Enum.count(posts),
25
# page_title: "Thoughts and Tidbits Blog: Bobby Experiment - muenster cheese skeet detection",
26
# meta_attrs: [
27
# %{name: "title", content: "Detect muenster cheese skeets coming across the wire, live from your back yard or device"},
28
# %{name: "description", content: "Try it, skeet something with the word muenster in it, and see if it appears here!"},
29
# %{property: "og:title", content: "Detect muenster cheese skeets coming across the wire, live from your back yard or device"},
30
# %{property: "og:description", content: "Try it, skeet something with the word muenster in it, and see if it appears here!"},
31
# %{property: "og:type", content: "website"}
32
# ]
33
# )}
34
# end
35
#
36
# def handle_info({:new_post, skeet}, socket) do
37
# posts = [%{
38
# text: skeet,
39
# timestamp: NaiveDateTime.local_now()
40
# } | socket.assigns.posts] |> Enum.take(@max_posts)
41
#
42
# {:noreply, assign(socket,
43
# posts: posts,
44
# total_count: socket.assigns.total_count + 1
45
# )}
46
# end
47
#
48
# def render(assigns) do
49
# ~H"""
50
# <.head_tags meta_attrs={@meta_attrs} page_title={@page_title} />
51
# <div class="p-4">
52
# <h1 class="text-2xl font-bold mb-4">Muenster Mentions</h1>
53
# <div class="text-sm text-gray-500 mb-4">
54
# Total mentions: <%= @total_count %>
55
# </div>
56
# <div class="space-y-4">
57
# <%= for post <- @posts do %>
58
# <div class="p-4 bg-white shadow rounded-lg border border-gray-200">
59
# <p class="text-gray-800 whitespace-pre-wrap"><%= post.text %></p>
60
# <div class="mt-2 text-xs text-gray-500">
61
# <%= Calendar.strftime(post.timestamp, "%Y-%m-%d %H:%M:%S") %>
62
# </div>
63
# </div>
64
# <% end %>
65
# <%= if Enum.empty?(@posts) do %>
66
# <p class="text-gray-500 italic">Waiting for posts mentioning muenster...</p>
67
# <% end %>
68
# </div>
69
# </div>
70
# """
71
# end
72
# end
73