Skip to content

Commit 17d182a

Browse files
committed
Use history navigation for detail back buttons
Clicking the back arrow in job and queue detail pages removed any applied params, as it dropped any non-id params on navigation. The new approach uses a history hook that leverages native window history instead. Closes #138
1 parent 6b8031a commit 17d182a

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

assets/js/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { loadAll } from "./lib/settings";
55

66
import Charter from "./hooks/charter";
77
import Completer from "./hooks/completer";
8+
import HistoryBack from "./hooks/history_back";
89
import Instantiator from "./hooks/instantiator";
910
import Refresher from "./hooks/refresher";
1011
import Relativize from "./hooks/relativize";
@@ -15,6 +16,7 @@ import Tippy from "./hooks/tippy";
1516
const hooks = {
1617
Charter,
1718
Completer,
19+
HistoryBack,
1820
Instantiator,
1921
Refresher,
2022
Relativize,

assets/js/hooks/history_back.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const HistoryBack = {
2+
mounted() {
3+
this.el.addEventListener("click", (event) => {
4+
event.preventDefault();
5+
6+
window.history.back();
7+
});
8+
},
9+
};
10+
11+
export default HistoryBack;

lib/oban/web/live/jobs/detail_component.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ defmodule Oban.Web.Jobs.DetailComponent do
99
~H"""
1010
<div id="job-details">
1111
<div class="flex justify-between items-center px-3 py-4 border-b border-gray-200 dark:border-gray-700">
12-
<.link
13-
patch={oban_path(:jobs, @params)}
12+
<button
1413
id="back-link"
15-
class="flex items-center hover:text-blue-500"
14+
class="flex items-center hover:text-blue-500 cursor-pointer bg-transparent border-0 p-0"
1615
data-title="Back to jobs"
17-
phx-hook="Tippy"
16+
phx-hook="HistoryBack"
17+
type="button"
1818
>
1919
<Icons.arrow_left class="w-5 h-5" />
2020
<span class="text-lg font-bold ml-2">Job Details</span>
21-
</.link>
21+
</button>
2222
2323
<div class="flex">
2424
<%= if can?(:cancel_jobs, @access) and cancelable?(@job) do %>

lib/oban/web/live/queues/detail_component.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ defmodule Oban.Web.Queues.DetailComponent do
6161
~H"""
6262
<div id="queue-details">
6363
<div class="flex justify-between items-center px-3 py-6">
64-
<.link patch={oban_path(:queues)} id="back-link" class="flex items-center hover:text-blue-500">
64+
<button
65+
id="back-link"
66+
class="flex items-center hover:text-blue-500 cursor-pointer bg-transparent border-0 p-0"
67+
phx-hook="HistoryBack"
68+
type="button"
69+
>
6570
<Icons.arrow_left class="w-5 h-5" />
6671
<span class="text-lg capitalize font-bold ml-2">{@queue} Queue</span>
67-
</.link>
72+
</button>
6873
</div>
6974
7075
<table class="table-fixed w-full bg-blue-50 dark:bg-blue-300 dark:bg-opacity-25">

0 commit comments

Comments
 (0)