-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add state check for updates and implement daisyUI
- Loading branch information
1 parent
927dd0e
commit bcd7005
Showing
8 changed files
with
139 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package app | ||
|
||
import ( | ||
"net/http" | ||
|
||
"jenn-ai/internal/state" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func getCurrentState(c *gin.Context) { | ||
appState := state.GetState() | ||
c.JSON(http.StatusOK, gin.H{ | ||
"platform": appState.GetPlatform(), | ||
"model": appState.GetModel(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package state | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
type AppState struct { | ||
mu sync.RWMutex | ||
platform string | ||
model string | ||
} | ||
|
||
var ( | ||
state *AppState | ||
once sync.Once | ||
) | ||
|
||
func GetState() *AppState { | ||
once.Do(func() { | ||
state = &AppState{} | ||
}) | ||
return state | ||
} | ||
|
||
func (s *AppState) SetPlatform(platform string) { | ||
s.mu.Lock() | ||
defer s.mu.Unlock() | ||
s.platform = platform | ||
} | ||
|
||
func (s *AppState) GetPlatform() string { | ||
s.mu.RLock() | ||
defer s.mu.RUnlock() | ||
return s.platform | ||
} | ||
|
||
func (s *AppState) SetModel(model string) { | ||
s.mu.Lock() | ||
defer s.mu.Unlock() | ||
s.model = model | ||
} | ||
|
||
func (s *AppState) GetModel() string { | ||
s.mu.RLock() | ||
defer s.mu.RUnlock() | ||
return s.model | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,41 @@ | ||
{{define "dropdowns.html"}} | ||
<div class="flex justify-left"> | ||
<div class="pr-2"> | ||
<button | ||
id="platform-trigger" | ||
<div class="flex flex-row items-center space-x-4"> | ||
<form id="platform-model-form" | ||
class="flex-grow flex flex-row space-x-2" | ||
hx-post="/select-model" | ||
hx-trigger="change from:#model-select" | ||
hx-target="#current-state" | ||
> | ||
<select | ||
name="platform-option" | ||
class="select select-ghost w-full max-w-xs" | ||
hx-get="/model-platform" | ||
hx-trigger="click" | ||
hx-target="#platform-container" | ||
class="bg-blue-500 hover:bg-blue-700 py-2 px-2 rounded" | ||
>Model Platform</button> | ||
<div | ||
id="platform-container" | ||
class="hidden mt-2 py-2 w-48 bg-black rounded-md shadow-xl z-20" | ||
></div> | ||
</div> | ||
<div class="pr-2"> | ||
<button | ||
id="model-trigger" | ||
hx-trigger="load" | ||
hx-target="this" | ||
hx-on::after-request="htmx.trigger('#model-select', 'reset')" | ||
> | ||
<option disabled selected value="">Model Platform</option> | ||
</select> | ||
|
||
<select | ||
id="model-select" | ||
name="model-option" | ||
class="select select-ghost w-full max-w-xs" | ||
hx-get="/model" | ||
hx-trigger="click" | ||
hx-target="#model-container" | ||
class="bg-blue-500 hover:bg-blue-700 py-2 px-2 rounded" | ||
>Model</button> | ||
<div | ||
id="model-container" | ||
class="hidden mt-2 py-2 w-48 bg-black rounded-md shadow-xl z-20" | ||
></div> | ||
hx-trigger="reset, change from:select[name='platform-option']" | ||
hx-target="this" | ||
hx-include="[name='platform-option']" | ||
> | ||
<option disabled selected value="">Select Model</option> | ||
</select> | ||
</form> | ||
<div | ||
id="current-state" | ||
hx-get="/current-state" | ||
hx-trigger="load, every 5s" | ||
class="badge badge-accent badge-outline" | ||
> | ||
<!-- This will be populated with the current state --> | ||
</div> | ||
<div id="selected-platform" class="mt-2 p-2"></div> | ||
<div id="selected-model" class="mt-2 p-2"></div> | ||
</div> | ||
|
||
<script> | ||
const container = document.getElementById('platform-container'); | ||
const selectedItemPlaceholder = document.getElementById('selected-platform'); | ||
const modelContainer = document.getElementById('model-container'); | ||
const selectedModel = document.getElementById('selected-model'); | ||
|
||
document.addEventListener('click', function (e) { | ||
if (e.target.matches('#platform-trigger')) { | ||
// Toggle dropdown visibility | ||
container.classList.toggle('hidden'); | ||
} | ||
if (e.target.matches('.platform-item')) { | ||
const selection = e.target.getAttribute('data-value'); | ||
selectedItemPlaceholder.textContent = `${selection}:`; | ||
// Toggle dropdown visibility | ||
container.classList.toggle('hidden'); | ||
e.preventDefault(); | ||
} | ||
if (e.target.matches('#model-trigger')) { | ||
// Toggle dropdown visibility | ||
modelContainer.classList.toggle('hidden'); | ||
} | ||
if (e.target.matches('.model-item')) { | ||
const selection = e.target.getAttribute('data-value'); | ||
selectedModel.textContent = `${selection}`; | ||
// Toggle dropdown visibility | ||
modelContainer.classList.toggle('hidden'); | ||
e.preventDefault(); | ||
} | ||
}); | ||
</script> | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
<html lang="en"> | ||
<head> | ||
<title>JennAI</title> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/full.min.css" rel="stylesheet" type="text/css" /> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<script src="https://unpkg.com/[email protected]" | ||
integrity="sha384-EAzY246d6BpbWR7sQ8+WEm40J8c3dHFsqC58IgPlh4kMbRRI6P6WA+LA/qGAyAu8" | ||
|
@@ -17,10 +18,23 @@ | |
</head> | ||
<body class="bg-gray-900"> | ||
<div class="bg-gray-200 dark:bg-gray-700 text-gray-900 dark:text-gray-100 p-4"> | ||
<p style="font-size: 24px; text-align: center;">{{.Message}}</p> | ||
<div class="pl-40"> | ||
{{template "dropdowns.html" .}} | ||
<div class="flex w-full"> | ||
<div class="card bg-base-300 rounded-box grid h-20 flex-grow place-items-center"> | ||
<p style="font-size: 24px; text-align: center;">{{.Message}}</p> | ||
<div class="pl-40"> | ||
{{template "dropdowns.html" .}} | ||
</div> | ||
</div> | ||
<div class="card bg-base-300 rounded-box grid h-20 flex-grow place-items-center"> | ||
<label class="flex cursor-pointer gap-2"> | ||
<span class="label-text">Current</span> | ||
<input type="checkbox" value="synthwave" class="toggle theme-controller" /> | ||
<span class="label-text">Synthwave</span> | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
<div id="htmlOutput" class="flex flex-col flex-grow pl-40 pr-40 mb-20"> | ||
|