Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live homepage #259

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions handlers/core/home.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package core

import (
"time"

"github.com/gofiber/fiber/v2"

"userstyles.world/handlers/jwt"
"userstyles.world/modules/cache"
"userstyles.world/modules/log"
"userstyles.world/modules/storage"
)
Expand All @@ -32,27 +29,37 @@ func Home(c *fiber.Ctx) error {
}
*/

Styles:
featured, found := cache.Store.Get("featuredStyles")
if !found {
styles, err := storage.FindStyleCardsFeatured()
if err != nil {
log.Warn.Println("Couldn't get featured styles, due", err)
return c.Render("core/home", fiber.Map{
"Title": "Home",
"User": u,
"Styles": nil,
})
}
cache.Store.Set("featuredStyles", styles, 5*time.Minute)

goto Styles
//Styles:
//featured, found := cache.Store.Get("featuredStyles")
updatedStyles, err := storage.FindStyleCardsPaginated(1, 4, "styles.updated_at DESC")
if err != nil {
//idk
}
addedStyles, err := storage.FindStyleCardsPaginated(1, 4, "styles.created_at DESC")
if err != nil {
//idk
}
//if !found {
featured, err := storage.FindStyleCardsFeatured()
if err != nil {
log.Warn.Println("Couldn't get featured styles, due", err)
return c.Render("core/home", fiber.Map{
"Title": "Home",
"User": u,
"Styles": nil,
})
}
// cache.Store.Set("featuredStyles", styles, 5*time.Minute)

// goto Styles
//}

return c.Render("core/home", fiber.Map{
"Title": "Website themes and skins",
"User": u,
"Styles": featured,
"Title": "Website themes and skins",
"User": u,
"Styles": featured,
"UpdatedStyles": updatedStyles,
"AddedStyles": addedStyles,
// "Stats": stats,
})
}
2 changes: 1 addition & 1 deletion modules/storage/style_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func FindStyleCardsFeatured() ([]StyleCard, error) {

err := database.Conn.
Select(selectCards).
Find(&res, "deleted_at IS NULL AND featured = 1").Error
Find(&res, "deleted_at IS NULL AND featured = 1 order by random() limit 16").Error
if err != nil {
return nil, err
}
Expand Down
26 changes: 25 additions & 1 deletion web/views/core/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,31 @@
<h2 class="ta:c">Featured userstyles</h2>
<p class="ta:c mb:l fg:2">See more styles on <a href="/explore">Explore</a> page.</p>
<div class="grid flex rwrap mx:r mt:m">
{{ range .Styles }}
{{ range slice .Styles 0 8 }}
{{ template "partials/style-card" . }}
{{ end }}
</div>
<div class="flex ai:c">
<h2>Recently Updated</h2>
<a class="ml:a mt:m" href="/explore?sort=recentlyupdated">More -></a>
</div>
<div class="grid flex rwrap mx:r mt:m">
{{ range .UpdatedStyles }}
{{ template "partials/style-card" . }}
{{ end }}
</div>
<div class="flex ai:c">
<h2>Recently Added</h2>
<a class="ml:a mt:m" href="/explore?sort=newest">More -></a>
</div>
<div class="grid flex rwrap mx:r mt:m">
{{ range .AddedStyles }}
{{ template "partials/style-card" . }}
{{ end }}
</div>
<h2>More Featured</h2>
<div class="grid flex rwrap mx:r mt:m">
{{ range slice .Styles 8 16 }}
{{ template "partials/style-card" . }}
{{ end }}
</div>
Expand Down