Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elixirus/token_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ defmodule Elixirus.TokenWorker do
%Client{} = client = Client.get_client(token)

case SnakeArgs.from_params(:elixirus, :announcements, [client])
|> python!(timeout: 10_000) do
|> python!(python_timeout: 10_000) do
{:error, :timeout} ->
Logger.info("Timed out refreshing")

Expand Down
2 changes: 2 additions & 0 deletions lib/elixirus_web/components/layouts/app.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<button id="logout-button" phx-hook="logout_button">
<Heroicons.arrow_right_on_rectangle class="w-12 hover:cursor-pointer hover:text-red-600 hover:translate-x-2 transition duration-500" />
</button>

<.link navigate={~p"/student/refresh"}><Heroicons.arrow_path class="h-12 w-12"/></.link>
</:misc>
</.header>
</header>
Expand Down
20 changes: 20 additions & 0 deletions lib/elixirus_web/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,30 @@ defmodule ElixirusWeb.Helpers do
end

def cache_and_ttl_data(user_id, cache_type, data, expiry_time \\ 5) do
Cachex.get_and_update(:elixirus_cache, user_id, fn caches ->
if caches != nil do
[cache_type | caches]
else
[cache_type]
end

end)
Cachex.put(:elixirus_cache, user_id <> cache_type, data)
Cachex.expire(:elixirus_cache, user_id <> cache_type, :timer.minutes(expiry_time))
end

def purge_user_cache(user_id) do
case Cachex.get(:elixirus_cache, user_id) do
{:ok, nil} -> :ok
{:ok, user_caches} -> Enum.each(user_caches, fn cache ->
Cachex.del(:elixirus_cache, user_id <> cache)
end)
_ -> :ok
end
Cachex.del(:elixirus_cache, user_id)
:ok
end

def handle_cache_data(user_id, cache_type) do
Cachex.purge(:elixirus_cache)

Expand Down
2 changes: 1 addition & 1 deletion lib/elixirus_web/live/student_live/attendance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ defmodule ElixirusWeb.StudentLive.Attendance do
end)
|> create_fetcher(user_id, subject_frequency, :subject_frequency, fn ->
SnakeArgs.from_params(:elixirus, :subject_frequency, [client])
|> Venomous.python!(timeout: 15_000)
|> Venomous.python!(python_timeout: 20_000)
end)
|> create_fetcher(user_id, attendance, :attendance, fn ->
{SnakeArgs.from_params(:elixirus, :attendance, [client, true])
Expand Down
14 changes: 13 additions & 1 deletion lib/elixirus_web/live/student_live/attendance.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,20 @@
</div>
</div>

<.link
:if={@live_action == nil}
class="h-20 rounded bg-fg shadow-md flex items-center justify-center"
navigate={~p"/student/attendance/subjects"}
replace={false}
>
View subject frequency
</.link>
<div :if={@live_action == :subject_frequency && :subject_frequency in @loadings}>
Loading...
</div>

<div
:if={@subject_frequency != []}
:if={@live_action == :subject_frequency && :subject_frequency not in @loadings}
class="flex flex-col gap-y-4 xl:max-h-[400px] md:flex-wrap items-center "
>
<div :for={{subj, freq} <- @subject_frequency} class="select-none w-full xl:w-1/4">
Expand Down
4 changes: 1 addition & 3 deletions lib/elixirus_web/live/student_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ defmodule ElixirusWeb.StudentLive.Index do
:attendance => attendance_discards,
:announcement => announcement_discards
}
|> dbg

{:noreply, push_event(socket, "discard-all", discards)}
end
Expand Down Expand Up @@ -590,15 +589,14 @@ defmodule ElixirusWeb.StudentLive.Index do
{key, val} <-
@info
|> Map.to_list()
|> dbg
}
phx-hook="expand_click"
id="info"
class="line-clamp-3 flex-wrap break-all flex bg-lighterbg w-24 max-w-24 p-1 rounded-md my-1"
>
<div class="flex flex-col">
<span><%= key %></span>
<div class="flex flex-row gap-x-1">
<div :if={val != ""} class="flex flex-row gap-x-1">
<p :for={val <- Map.values(val)} :if={val != ""}>
<%= val %>
</p>
Expand Down
16 changes: 16 additions & 0 deletions lib/elixirus_web/live/student_live/refresh.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule ElixirusWeb.StudentLive.Refresh do

use ElixirusWeb, :live_view
import ElixirusWeb.Helpers, only: [purge_user_cache: 1]

def mount(_params, %{"user_id" => user_id}, socket) do
purge_user_cache(user_id)
{:ok, push_navigate(socket, to: ~p"/")}
end

def render(assigns) do
~H"""
<h1>cache cleared</h1>
"""
end
end
2 changes: 2 additions & 0 deletions lib/elixirus_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ defmodule ElixirusWeb.Router do
scope "/student" do
pipe_through :api_token
live "/", StudentLive.Index
live "/refresh", StudentLive.Refresh
live "/announcements", StudentLive.Announcements
live "/timetable", StudentLive.Timetable
live "/schedule", StudentLive.Schedule
live "/homework", StudentLive.Homework

scope "/attendance" do
live "/", StudentLive.Attendance
live "/subjects", StudentLive.Attendance, :subject_frequency
live "/:href", StudentLive.Attendance, :view
end

Expand Down
Loading