Added Settings for Manga ordering, fixed theme selector
This commit is contained in:
@@ -13,16 +13,6 @@ const (
|
|||||||
Updated
|
Updated
|
||||||
)
|
)
|
||||||
|
|
||||||
//type Table[K comparable, T any] interface {
|
|
||||||
// Get(key K) (T, bool)
|
|
||||||
// Set(key K, new T)
|
|
||||||
// All() []T
|
|
||||||
// Delete(key K) error
|
|
||||||
// Save(db *sql.DB) error
|
|
||||||
// Load(db *sql.DB) error
|
|
||||||
// Connect(key K, value *any) bool
|
|
||||||
//}
|
|
||||||
|
|
||||||
type DbTable[K comparable, T any] struct {
|
type DbTable[K comparable, T any] struct {
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
items map[K]T
|
items map[K]T
|
||||||
@@ -56,14 +46,6 @@ func (d *DbTable[K, T]) Get(key K) (T, bool) {
|
|||||||
return val, ok
|
return val, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRef unsafe
|
|
||||||
func (d *DbTable[K, T]) getRef(key K) (*T, bool) {
|
|
||||||
d.mutex.Lock()
|
|
||||||
defer d.mutex.Unlock()
|
|
||||||
val, ok := d.items[key]
|
|
||||||
return &val, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DbTable[K, T]) Set(key K, new T) {
|
func (d *DbTable[K, T]) Set(key K, new T) {
|
||||||
d.mutex.Lock()
|
d.mutex.Lock()
|
||||||
defer d.mutex.Unlock()
|
defer d.mutex.Unlock()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (s *Server) HandleNew(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Redirect(w, r, "/current/", http.StatusTemporaryRedirect)
|
http.Redirect(w, r, "/current/", http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) HandleMenu(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
||||||
tmpl := template.Must(view.GetViewTemplate(view.Menu))
|
tmpl := template.Must(view.GetViewTemplate(view.Menu))
|
||||||
all := s.DbMgr.Mangas.All()
|
all := s.DbMgr.Mangas.All()
|
||||||
l := len(all)
|
l := len(all)
|
||||||
@@ -108,9 +108,9 @@ func (s *Server) HandleMenu(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
n = time.Now().UnixNano()
|
n = time.Now().UnixNano()
|
||||||
|
|
||||||
sort := r.URL.Query().Get("sort")
|
order, ok := s.DbMgr.Settings.Get("order")
|
||||||
|
sort := order.Value
|
||||||
if sort == "" || sort == "title" {
|
if !ok || sort == "title" {
|
||||||
slices.SortStableFunc(mangaViewModels, func(a, b view.MangaViewModel) int {
|
slices.SortStableFunc(mangaViewModels, func(a, b view.MangaViewModel) int {
|
||||||
return cmp.Compare(a.Title, b.Title)
|
return cmp.Compare(a.Title, b.Title)
|
||||||
})
|
})
|
||||||
@@ -337,6 +337,23 @@ func (s *Server) HandlePrev(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Redirect(w, r, "/current/", http.StatusTemporaryRedirect)
|
http.Redirect(w, r, "/current/", http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) HandleSettingSet(w http.ResponseWriter, r *http.Request) {
|
||||||
|
settingName := r.PathValue("setting")
|
||||||
|
settingValue := r.PathValue("value")
|
||||||
|
|
||||||
|
setting, ok := s.DbMgr.Settings.Get(settingName)
|
||||||
|
if !ok {
|
||||||
|
s.DbMgr.Settings.Set(settingName, database.NewSetting(settingName, settingValue))
|
||||||
|
} else {
|
||||||
|
if setting.Value != settingValue {
|
||||||
|
setting.Value = settingValue
|
||||||
|
s.DbMgr.Settings.Set(settingName, setting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) HandleSetting(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) HandleSetting(w http.ResponseWriter, r *http.Request) {
|
||||||
settingName := r.PostFormValue("setting")
|
settingName := r.PostFormValue("setting")
|
||||||
settingValue := r.PostFormValue(settingName)
|
settingValue := r.PostFormValue(settingName)
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ func (s *Server) Start(port int) error {
|
|||||||
http.HandleFunc("POST /delete", s.HandleDelete)
|
http.HandleFunc("POST /delete", s.HandleDelete)
|
||||||
http.HandleFunc("/favicon.ico", s.HandleFavicon)
|
http.HandleFunc("/favicon.ico", s.HandleFavicon)
|
||||||
http.HandleFunc("POST /setting/", s.HandleSetting)
|
http.HandleFunc("POST /setting/", s.HandleSetting)
|
||||||
|
http.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
|
||||||
|
|
||||||
// Update Latest Chapter every 5 Minutes
|
// Update Latest Chapter every 5 Minutes
|
||||||
go func(s *Server) {
|
go func(s *Server) {
|
||||||
|
|||||||
@@ -18,6 +18,11 @@
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.white {
|
||||||
|
background-color: white;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
.button-36 {
|
.button-36 {
|
||||||
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -116,17 +121,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<script>
|
|
||||||
function myFunction(theme) {
|
|
||||||
if (theme !== "white") {
|
|
||||||
var element = document.body;
|
|
||||||
element.classList.toggle(theme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body onload="myFunction({{(index .Settings "theme").Value}})">
|
<body class="{{(index .Settings "theme").Value}}">
|
||||||
<form method="post" action="/new/">
|
<form method="post" action="/new/">
|
||||||
<label>
|
<label>
|
||||||
New Sub Url
|
New Sub Url
|
||||||
@@ -138,9 +134,8 @@
|
|||||||
<form method="post" action="/setting/">
|
<form method="post" action="/setting/">
|
||||||
<label for="theme">Theme</label>
|
<label for="theme">Theme</label>
|
||||||
<select onchange="this.form.submit()" id="theme" name="theme">
|
<select onchange="this.form.submit()" id="theme" name="theme">
|
||||||
<option value="" selected disabled hidden>Choose Theme</option>
|
<option {{if eq (index .Settings "theme").Value "white"}} selected {{end}} value="white">White</option>
|
||||||
<option value="white">White</option>
|
<option {{if eq (index .Settings "theme").Value "dark"}} selected {{end}} value="dark">Dark</option>
|
||||||
<option value="dark">Dark</option>
|
|
||||||
</select>
|
</select>
|
||||||
<input type="hidden" name="setting" value="theme">
|
<input type="hidden" name="setting" value="theme">
|
||||||
</form>
|
</form>
|
||||||
@@ -148,9 +143,9 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Thumbnail</th>
|
<th>Thumbnail</th>
|
||||||
<th class="table-left"><a href="?sort=title">Title</a></th>
|
<th class="table-left"><a href="setting/set/order/title">Title</a></th>
|
||||||
<th><a href="?sort=chapter">Current Chapter</a></th>
|
<th><a href="setting/set/order/chapter">Current Chapter</a></th>
|
||||||
<th><a href="?sort=last">Last Accessed</a></th>
|
<th><a href="setting/set/order/last">Last Accessed</a></th>
|
||||||
<th>Link</th>
|
<th>Link</th>
|
||||||
<th>Delete</th>
|
<th>Delete</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user