Skip to content

Commit e36b79c

Browse files
committed
Setup Alba for Inertia
1 parent d3c90ad commit e36b79c

31 files changed

+180
-63
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ build
33
coverage
44

55
app/frontend/routes
6+
app/frontend/types/serializers

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ gem "authentication-zero"
4949
# Brings Rails named routes to javascript
5050
gem "js-routes"
5151

52+
# Use Abla and Typelizer for CoC rendering
53+
gem "alba", "~> 3.10"
54+
gem "alba-inertia", "~> 0.1.2"
55+
gem "typelizer", "~> 0.5.4"
56+
5257
group :development, :test do
5358
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
5459
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"

Gemfile.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,17 @@ GEM
7777
uri (>= 0.13.1)
7878
addressable (2.8.8)
7979
public_suffix (>= 2.0.2, < 8.0)
80+
alba (3.10.0)
81+
alba-inertia (0.1.2)
82+
alba
83+
inertia_rails
84+
zeitwerk
8085
ast (2.4.3)
8186
authentication-zero (4.0.3)
8287
base64 (0.3.0)
8388
bcrypt (3.1.20)
8489
bcrypt_pbkdf (1.1.2)
90+
benchmark (0.5.0)
8591
bigdecimal (3.3.1)
8692
bindex (0.8.1)
8793
bootsnap (1.19.0)
@@ -378,6 +384,9 @@ GEM
378384
thruster (0.1.16-x86_64-linux)
379385
timeout (0.5.0)
380386
tsort (0.2.0)
387+
typelizer (0.5.4)
388+
benchmark
389+
railties (>= 6.0.0)
381390
tzinfo (2.0.6)
382391
concurrent-ruby (~> 1.0)
383392
unicode-display_width (3.2.0)
@@ -420,6 +429,8 @@ PLATFORMS
420429
x86_64-linux-musl
421430

422431
DEPENDENCIES
432+
alba (~> 3.10)
433+
alba-inertia (~> 0.1.2)
423434
authentication-zero
424435
bcrypt (~> 3.1.7)
425436
bootsnap
@@ -445,6 +456,7 @@ DEPENDENCIES
445456
solid_queue
446457
sqlite3 (>= 2.1)
447458
thruster
459+
typelizer (~> 0.5.4)
448460
tzinfo-data
449461
vite_rails (~> 3.0)
450462
web-console

app/controllers/identity/password_resets_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def new
99
end
1010

1111
def edit
12-
render inertia: {email: @user.email, sid: params[:sid]}
12+
@email = @user.email
13+
@sid = params[:sid]
1314
end
1415

1516
def create

app/controllers/inertia_controller.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# frozen_string_literal: true
22

33
class InertiaController < ApplicationController
4-
inertia_config default_render: true
5-
inertia_share flash: -> { flash.to_hash },
6-
auth: {
7-
user: -> { Current.user.as_json(only: %i[id name email verified created_at updated_at]) },
8-
session: -> { Current.session.as_json(only: %i[id]) }
9-
}
4+
include Alba::Inertia::Controller
5+
6+
inertia_share { SharedPropsSerializer.new(self).to_inertia }
107

118
private
129

app/controllers/settings/sessions_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
class Settings::SessionsController < InertiaController
44
def index
5-
sessions = Current.user.sessions.order(created_at: :desc)
6-
7-
render inertia: {sessions: sessions.as_json(only: %i[id user_agent ip_address created_at])}
5+
@sessions = Current.user.sessions.order(created_at: :desc)
86
end
97
end

app/controllers/users_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class UsersController < InertiaController
55
before_action :require_no_authentication, only: %i[new create]
66

77
def new
8-
@user = User.new
98
end
109

1110
def create

app/frontend/components/app-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
213213
<DropdownMenuTrigger asChild>
214214
<Button variant="ghost" className="size-10 rounded-full p-1">
215215
<Avatar className="size-8 overflow-hidden rounded-full">
216-
<AvatarImage src={auth.user.avatar} alt={auth.user.name} />
216+
<AvatarImage alt={auth.user.name} />
217217
<AvatarFallback className="rounded-lg bg-neutral-200 text-black dark:bg-neutral-700 dark:text-white">
218218
{getInitials(auth.user.name)}
219219
</AvatarFallback>

app/frontend/components/user-info.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function UserInfo({
1414
return (
1515
<>
1616
<Avatar className="h-8 w-8 overflow-hidden rounded-full">
17-
<AvatarImage src={user.avatar} alt={user.name} />
17+
<AvatarImage alt={user.name} />
1818
<AvatarFallback className="rounded-lg bg-neutral-200 text-black dark:bg-neutral-700 dark:text-white">
1919
{getInitials(user.name)}
2020
</AvatarFallback>

app/frontend/components/user-menu-content.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ import {
1010
import { UserInfo } from "@/components/user-info"
1111
import { useMobileNavigation } from "@/hooks/use-mobile-navigation"
1212
import { sessionPath, settingsProfilePath } from "@/routes"
13-
import type { User } from "@/types"
13+
import type { SharedProps } from "@/types"
1414

1515
interface UserMenuContentProps {
16-
auth: {
17-
session: {
18-
id: string
19-
}
20-
user: User
21-
}
16+
auth: SharedProps["auth"]
2217
}
2318

2419
export function UserMenuContent({ auth }: UserMenuContentProps) {

0 commit comments

Comments
 (0)