inter-hub-haskell/Web/View/Widgets/Index.hs

70 lines
2.6 KiB
Haskell
Raw Normal View History

module Web.View.Widgets.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
data IndexView = IndexView
{ widgets :: ![Widget]
, hubs :: ![Hub]
}
instance View IndexView where
html IndexView { .. } = [hsx|
<div class="flex items-center justify-between mb-6">
<h1 class="text-2xl font-semibold">Widgets</h1>
<a href={NewWidgetAction}
class="bg-indigo-600 text-white text-sm font-medium px-4 py-2 rounded hover:bg-indigo-700">
Register Widget
</a>
</div>
<div class="bg-white rounded-lg border border-gray-200 overflow-hidden">
<table class="w-full text-sm">
<thead class="bg-gray-50 border-b border-gray-200">
<tr>
<th class="text-left px-4 py-3 font-medium text-gray-700">Name</th>
<th class="text-left px-4 py-3 font-medium text-gray-700">Hub</th>
<th class="text-left px-4 py-3 font-medium text-gray-700">Type</th>
<th class="text-left px-4 py-3 font-medium text-gray-700">Status</th>
<th class="text-left px-4 py-3 font-medium text-gray-700">Version</th>
<th class="px-4 py-3"></th>
</tr>
</thead>
<tbody>
{forEach widgets (renderWidget hubs)}
</tbody>
</table>
</div>
|]
renderWidget :: [Hub] -> Widget -> Html
renderWidget hubs w = [hsx|
<tr class="border-b border-gray-100 hover:bg-gray-50">
<td class="px-4 py-3">
<a href={ShowWidgetAction { widgetId = w.id }}
class="font-medium text-indigo-600 hover:text-indigo-800">
{w.name}
</a>
</td>
<td class="px-4 py-3 text-gray-500">{hubName hubs w.hubId}</td>
<td class="px-4 py-3 text-gray-500">{w.widgetType}</td>
<td class="px-4 py-3">
<span class="inline-block px-2 py-0.5 rounded text-xs bg-green-100 text-green-800">
{w.status}
</span>
</td>
<td class="px-4 py-3 text-gray-500 text-xs">v{show w.version}</td>
<td class="px-4 py-3 text-right">
<a href={EditWidgetAction { widgetId = w.id }}
class="text-gray-500 hover:text-gray-700 text-xs">Edit</a>
</td>
</tr>
|]
hubName :: [Hub] -> Id Hub -> Text
hubName hubs hubId =
case find (\h -> h.id == hubId) hubs of
Just h -> h.name
Nothing -> ""