summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--models/folders.go9
-rw-r--r--repository/folders.go58
-rw-r--r--static/css/main.css17
-rw-r--r--static/icons/dog.pngbin0 -> 84737 bytes
-rw-r--r--static/icons/dog_open.pngbin0 -> 85772 bytes
-rw-r--r--static/icons/encrypt.pngbin0 -> 31006 bytes
-rw-r--r--static/icons/encrypt_open.pngbin0 -> 33154 bytes
-rw-r--r--static/icons/folder.pngbin0 -> 32823 bytes
-rw-r--r--static/icons/folder_open.pngbin0 -> 69270 bytes
-rw-r--r--static/icons/inbox.pngbin0 -> 27645 bytes
-rw-r--r--static/icons/inbox_open.pngbin0 -> 94875 bytes
-rw-r--r--tags/tags.go2
-rw-r--r--templates/partials/sidebar.django16
-rw-r--r--types/email.go5
14 files changed, 85 insertions, 22 deletions
diff --git a/models/folders.go b/models/folders.go
index 6c3800a..d823ba0 100644
--- a/models/folders.go
+++ b/models/folders.go
@@ -8,10 +8,11 @@ type Folder struct {
gorm.Model
UserEmail string `gorm:"index"`
- Name string
- IMAPName string
- Icon string
- ParentID *uint
+ Name string
+ IMAPName string
+ IconOpen string
+ IconClose string
+ ParentID *uint
UnreadCount int `gorm:"default:0"`
TotalCount int `gorm:"default:0"`
diff --git a/repository/folders.go b/repository/folders.go
index 973727a..63ccf88 100644
--- a/repository/folders.go
+++ b/repository/folders.go
@@ -3,6 +3,7 @@ package repository
import (
"lain/database"
"lain/models"
+ "lain/types"
"lain/utils/crypto"
"lain/utils/email"
"net/url"
@@ -11,7 +12,24 @@ import (
"github.com/gofiber/fiber/v2"
)
-const defaultFolderIcon = "/static/images/icons/folder.png"
+var folderIcons = map[string]types.FolderIconVariant{
+ "default": {
+ Open: "/static/icons/folder_open.png",
+ Close: "/static/icons/folder.png",
+ },
+ "inbox": {
+ Open: "/static/icons/inbox_open.png",
+ Close: "/static/icons/inbox.png",
+ },
+ "encrypt": {
+ Open: "/static/icons/encrypt_open.png",
+ Close: "/static/icons/encrypt.png",
+ },
+ "dog": {
+ Open: "/static/icons/dog_open.png",
+ Close: "/static/icons/dog.png",
+ },
+}
func GetFolders(userEmail, activeFolder string) []fiber.Map {
syncFolders(userEmail)
@@ -25,18 +43,14 @@ func GetFolders(userEmail, activeFolder string) []fiber.Map {
var rootFolders []fiber.Map
for _, folder := range allFolders {
- icon := folder.Icon
- if icon == "" {
- icon = defaultFolderIcon
- }
-
displayName := getDisplayName(folder.IMAPName)
folderData := fiber.Map{
"ID": folder.ID,
"Name": displayName,
"IMAPName": folder.IMAPName,
- "Icon": icon,
+ "IconOpen": folder.IconOpen,
+ "IconClose": folder.IconClose,
"UnreadCount": folder.UnreadCount,
"Active": false,
"ParentID": folder.ParentID,
@@ -127,6 +141,26 @@ func sortFolders(folders []models.Folder) {
}
}
+func getFolderType(folderName string) string {
+ nameLower := strings.ToLower(folderName)
+
+ if strings.Contains(folderName, "/") {
+ parts := strings.Split(folderName, "/")
+ nameLower = strings.ToLower(parts[len(parts)-1])
+ }
+
+ for iconType := range folderIcons {
+ if iconType == "default" {
+ continue
+ }
+ if strings.Contains(nameLower, iconType) {
+ return iconType
+ }
+ }
+
+ return "default"
+}
+
func syncFolders(userEmail string) error {
var prefs models.Preferences
if err := database.DB.Where("email = ?", userEmail).First(&prefs).Error; err != nil {
@@ -157,13 +191,16 @@ func syncFolders(userEmail string) error {
result := database.DB.Where("user_email = ? AND LOWER(imap_name) = ?", userEmail, imapNameLower).First(&folder)
sortOrder := getSortOrder(imapFolder.Name, i)
+ folderType := getFolderType(imapFolder.Name)
+ iconVariant := folderIcons[folderType]
if result.Error != nil {
folder = models.Folder{
UserEmail: userEmail,
Name: imapFolder.Name,
IMAPName: imapFolder.Name,
- Icon: defaultFolderIcon,
+ IconOpen: iconVariant.Open,
+ IconClose: iconVariant.Close,
SortOrder: sortOrder,
}
database.DB.Create(&folder)
@@ -171,9 +208,8 @@ func syncFolders(userEmail string) error {
} else {
folder.Name = imapFolder.Name
folder.SortOrder = sortOrder
- if folder.Icon == "" {
- folder.Icon = defaultFolderIcon
- }
+ folder.IconOpen = iconVariant.Open
+ folder.IconClose = iconVariant.Close
database.DB.Save(&folder)
foldersByName[imapNameLower] = folder.ID
}
diff --git a/static/css/main.css b/static/css/main.css
index 546eba1..84a1d59 100644
--- a/static/css/main.css
+++ b/static/css/main.css
@@ -118,7 +118,10 @@ footer a:hover {
padding: 3px 8px;
font-size: 10px;
cursor: pointer;
- display: block;
+ display: flex;
+ align-items: center;
+ gap: 2px;
+ flex-direction: column;
}
.nav-subitem a:hover {
@@ -131,6 +134,11 @@ footer a:hover {
cursor: not-allowed;
}
+.nav-subitem a img {
+ width: 16px;
+ height: 16px;
+}
+
.options-dropdown {
display: none;
position: absolute;
@@ -530,10 +538,11 @@ input[type="date"]:focus {
.folder-item a {
display: flex;
align-items: center;
- gap: 6px;
+ gap: 8px;
padding: 5px 8px;
color: var(--text-secondary);
font-size: 11px;
+ border-left: 2px solid var(--bg-secondary);
}
.folder-item a:hover {
@@ -548,8 +557,8 @@ input[type="date"]:focus {
}
.folder-icon {
- width: 14px;
- height: 14px;
+ width: 16px;
+ height: 16px;
}
.folder-name {
diff --git a/static/icons/dog.png b/static/icons/dog.png
new file mode 100644
index 0000000..22e0ac5
--- /dev/null
+++ b/static/icons/dog.png
Binary files differ
diff --git a/static/icons/dog_open.png b/static/icons/dog_open.png
new file mode 100644
index 0000000..f90b9c4
--- /dev/null
+++ b/static/icons/dog_open.png
Binary files differ
diff --git a/static/icons/encrypt.png b/static/icons/encrypt.png
new file mode 100644
index 0000000..5ab926f
--- /dev/null
+++ b/static/icons/encrypt.png
Binary files differ
diff --git a/static/icons/encrypt_open.png b/static/icons/encrypt_open.png
new file mode 100644
index 0000000..9274859
--- /dev/null
+++ b/static/icons/encrypt_open.png
Binary files differ
diff --git a/static/icons/folder.png b/static/icons/folder.png
new file mode 100644
index 0000000..0b86933
--- /dev/null
+++ b/static/icons/folder.png
Binary files differ
diff --git a/static/icons/folder_open.png b/static/icons/folder_open.png
new file mode 100644
index 0000000..0f88026
--- /dev/null
+++ b/static/icons/folder_open.png
Binary files differ
diff --git a/static/icons/inbox.png b/static/icons/inbox.png
new file mode 100644
index 0000000..f137c7a
--- /dev/null
+++ b/static/icons/inbox.png
Binary files differ
diff --git a/static/icons/inbox_open.png b/static/icons/inbox_open.png
new file mode 100644
index 0000000..da9e8b0
--- /dev/null
+++ b/static/icons/inbox_open.png
Binary files differ
diff --git a/tags/tags.go b/tags/tags.go
index 6229c20..a33b223 100644
--- a/tags/tags.go
+++ b/tags/tags.go
@@ -15,7 +15,7 @@ func Initialize() {
tags := []templateTag{
{"url", url},
- {"static", static},
+ // {"static", static},
}
for _, t := range tags {
diff --git a/templates/partials/sidebar.django b/templates/partials/sidebar.django
index ea0a72d..12df271 100644
--- a/templates/partials/sidebar.django
+++ b/templates/partials/sidebar.django
@@ -2,7 +2,13 @@
{% for folder in Folders %}
<li class="folder-item {% if folder.Active %}active{% endif %}">
<a href="/mail/{{ folder.IMAPName|lower }}">
- <img src="{{ folder.Icon }}" alt="{{ folder.Name }}" class="folder-icon" />
+ <img src="{% if folder.Active %}
+ {{ folder.IconOpen }}
+ {% else %}
+ {{ folder.IconClose }}
+ {% endif %}"
+ alt="{{ folder.Name }}"
+ class="folder-icon" />
<span class="folder-name">{{ folder.Name }}</span>
{% if folder.UnreadCount > 0 %}
<span class="folder-count">{{ folder.UnreadCount }}</span>
@@ -13,7 +19,13 @@
{% for subfolder in folder.Subfolders %}
<li class="folder-item subfolder {% if subfolder.Active %}active{% endif %}">
<a href="/mail/{{ subfolder.IMAPName|lower }}">
- <img src="{{ subfolder.Icon }}" alt="{{ subfolder.Name }}" class="folder-icon" />
+ <img src="{% if subfolder.Active %}
+ {{ subfolder.IconOpen }}
+ {% else %}
+ {{ subfolder.IconClose }}
+ {% endif %}"
+ alt="{{ subfolder.Name }}"
+ class="folder-icon" />
<span class="folder-name">{{ subfolder.Name }}</span>
{% if subfolder.UnreadCount > 0 %}
<span class="folder-count">{{ subfolder.UnreadCount }}</span>
diff --git a/types/email.go b/types/email.go
index d5cc8f5..1d30a9b 100644
--- a/types/email.go
+++ b/types/email.go
@@ -10,3 +10,8 @@ type IMAPFolder struct {
Name string
HasChildren bool
}
+
+type FolderIconVariant struct {
+ Open string
+ Close string
+}