Skip to content

Commit e481fb8

Browse files
author
ali
committed
draft: implemented hub, removed old one and done some plumbing
1 parent 1d63bf4 commit e481fb8

File tree

16 files changed

+421
-188
lines changed

16 files changed

+421
-188
lines changed

modules/core/presentation/templates/layouts/authenticated.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ templ Authenticated(props AuthenticatedProps) {
214214
Footer: SidebarFooter(pageCtx),
215215
}
216216
}}
217-
@Base(props.Title) {
217+
@Base(&BaseProps{Title: props.Title, WebsocketURL: "/ws"}) {
218218
@MobileSidebar(sidebarProps)
219219
<div class="grid min-h-screen w-full lg:grid-cols-[280px_1fr] overflow-y-auto">
220220
<div class="hidden lg:block">

modules/core/presentation/templates/layouts/authenticated_templ.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/core/presentation/templates/layouts/base.templ

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,28 @@ templ DefaultHead() {
3232
<script src={ htmxWS }></script>
3333
}
3434

35-
templ Base(title string) {
35+
type BaseProps struct {
36+
Title string
37+
WebsocketURL string
38+
}
39+
40+
templ Base(props *BaseProps) {
3641
<!DOCTYPE html>
3742
<html
3843
lang="en"
3944
class="system bg-surface-100 text-100"
4045
>
4146
<head>
42-
<title>{ title }</title>
47+
<title>{ props.Title }</title>
4348
<meta charset="UTF-8"/>
4449
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
4550
@composables.MustUseHead(ctx)
4651
</head>
47-
<body class="antialiased overflow-y-hidden">
52+
<body
53+
class="antialiased overflow-y-hidden"
54+
hx-ext="ws"
55+
ws-connect={ props.WebsocketURL }
56+
>
4857
{ children... }
4958
</body>
5059
</html>

modules/core/presentation/templates/layouts/base_templ.go

Lines changed: 23 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/core/presentation/templates/pages/error_pages/notfound.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
templ NotFoundContent() {
10-
@layouts.Base("Not found") {
10+
@layouts.Base(&layouts.BaseProps{Title: "Not found", WebsocketURL: "/ws"}) {
1111
<div class="flex flex-col items-center justify-center h-screen w-full">
1212
<div class="flex flex-col items-center">
1313
<img src="/assets/images/search.svg" class="w-32 h-32" alt="404"/>

modules/core/presentation/templates/pages/error_pages/notfound_templ.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/core/presentation/templates/pages/login/index.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ templ Header() {
7272

7373
templ Index(p *LoginProps) {
7474
{{ pageCtx := composables.UsePageCtx(ctx) }}
75-
@layouts.Base(pageCtx.T("Login.Meta.Title")) {
75+
@layouts.Base(&layouts.BaseProps{Title: pageCtx.T("Login.Meta.Title"), WebsocketURL: "/ws"}) {
7676
<div class="flex flex-col h-screen overflow-y-auto">
7777
@Header()
7878
<div class="flex-1 flex items-center justify-center">

modules/core/presentation/templates/pages/login/index_templ.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/crm/infrastructure/websocket/hub.go

Lines changed: 0 additions & 88 deletions
This file was deleted.

modules/crm/presentation/controllers/chat_controller.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import (
1919
"github.com/iota-uz/iota-sdk/modules/crm/domain/aggregates/chat"
2020
"github.com/iota-uz/iota-sdk/modules/crm/domain/aggregates/client"
2121
"github.com/iota-uz/iota-sdk/modules/crm/infrastructure/persistence"
22-
"github.com/iota-uz/iota-sdk/modules/crm/infrastructure/websocket"
2322
"github.com/iota-uz/iota-sdk/modules/crm/presentation/mappers"
24-
"github.com/iota-uz/iota-sdk/modules/crm/presentation/templates/pages/chats"
23+
chatsui "github.com/iota-uz/iota-sdk/modules/crm/presentation/templates/pages/chats"
2524
"github.com/iota-uz/iota-sdk/modules/crm/presentation/viewmodels"
2625
"github.com/iota-uz/iota-sdk/modules/crm/services"
2726
"github.com/iota-uz/iota-sdk/pkg/application"
@@ -42,7 +41,6 @@ type SendMessageDTO struct {
4241

4342
type ChatController struct {
4443
app application.Application
45-
wsHandler *websocket.Hub
4644
userService *coreservices.UserService
4745
templateService *services.MessageTemplateService
4846
clientService *services.ClientService
@@ -53,7 +51,6 @@ type ChatController struct {
5351
func NewChatController(app application.Application, basePath string) application.Controller {
5452
return &ChatController{
5553
app: app,
56-
wsHandler: websocket.NewHub(),
5754
userService: app.Service(coreservices.UserService{}).(*coreservices.UserService),
5855
clientService: app.Service(services.ClientService{}).(*services.ClientService),
5956
chatService: app.Service(services.ChatService{}).(*services.ChatService),
@@ -80,7 +77,6 @@ func (c *ChatController) Register(r *mux.Router) {
8077
router.HandleFunc("", c.List).Methods(http.MethodGet)
8178
router.HandleFunc("/search", c.Search).Methods(http.MethodGet)
8279
router.HandleFunc("/new", c.GetNew).Methods(http.MethodGet)
83-
router.Handle("/ws", c.wsHandler)
8480
router.HandleFunc("", c.Create).Methods(http.MethodPost)
8581
router.HandleFunc("/{id:[0-9]+}/messages", c.SendMessage).Methods(http.MethodPost)
8682

@@ -135,7 +131,6 @@ func (c *ChatController) onMessageAdded(event *chat.MessagedAddedEvent) {
135131
log.Printf("Error rendering chat messages: %v", err)
136132
return
137133
}
138-
c.wsHandler.Broadcast(buf.Bytes())
139134
c.broadcastChatsListUpdate(ctx)
140135
}
141136

@@ -159,7 +154,6 @@ func (c *ChatController) broadcastChatsListUpdate(ctx context.Context) {
159154
log.Printf("Error rendering chat list: %v", err)
160155
return
161156
}
162-
c.wsHandler.Broadcast(buf.Bytes())
163157
}
164158

165159
func (c *ChatController) messageTemplates(ctx context.Context) ([]*viewmodels.MessageTemplate, error) {
@@ -223,10 +217,9 @@ func (c *ChatController) renderChats(w http.ResponseWriter, r *http.Request) {
223217
}
224218

225219
props := chatsui.IndexPageProps{
226-
WebsocketURL: c.basePath + "/ws",
227-
SearchURL: c.basePath + "/search",
228-
NewChatURL: "/crm/chats/new",
229-
Chats: chatViewModels,
220+
SearchURL: c.basePath + "/search",
221+
NewChatURL: "/crm/chats/new",
222+
Chats: chatViewModels,
230223
}
231224
var component templ.Component
232225
isHxRequest := len(r.Header.Get("Hx-Request")) > 0

0 commit comments

Comments
 (0)