Skip to content

Commit

Permalink
Merge pull request #2708 from xtekky/10Feb
Browse files Browse the repository at this point in the history
Fix styling on mobile
  • Loading branch information
hlohaus authored Feb 12, 2025
2 parents 34b815b + 5676752 commit 292d5b6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 102 deletions.
3 changes: 1 addition & 2 deletions g4f/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os.path
import hashlib
import asyncio
from urllib.parse import quote_plus
from fastapi import FastAPI, Response, Request, UploadFile, Depends
from fastapi.middleware.wsgi import WSGIMiddleware
from fastapi.responses import StreamingResponse, RedirectResponse, HTMLResponse, JSONResponse
Expand Down Expand Up @@ -552,7 +551,7 @@ async def get_json(filename, request: Request):
HTTP_404_NOT_FOUND: {}
})
async def get_image(filename, request: Request):
target = os.path.join(images_dir, quote_plus(filename))
target = os.path.join(images_dir, os.path.basename(filename))
ext = os.path.splitext(filename)[1][1:]
stat_result = SimpleNamespace()
stat_result.st_size = 0
Expand Down
94 changes: 9 additions & 85 deletions g4f/gui/client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ ul {
justify-content: center;
align-items: center;
transition: all 0.3s ease;
padding: 10px 12px;
}

.mobile-sidebar i {
Expand Down Expand Up @@ -1421,11 +1422,12 @@ form .field.saved .fa-xmark {
line-height: 30px;
}

.collapsible {
.field.collapsible {
border: 1px solid var(--blur-border);
border-radius: var(--border-radius-1);
overflow: hidden;
margin-bottom: 10px;
padding-right: 0;
}

.collapsible-header {
Expand All @@ -1442,7 +1444,11 @@ form .field.saved .fa-xmark {
}

.collapsible-content {
padding: 10px;
padding: 0 10px;
}

.collapsible-content.api-key {
width: 100%;
}

.collapsible-content.hidden {
Expand Down Expand Up @@ -1539,6 +1545,7 @@ form .field.saved .fa-xmark {
.conversations, .settings, .conversation {
flex: 1 1 300px;
min-width: 0;
height: 100%;
}

/* Media queries for mobile devices */
Expand All @@ -1557,92 +1564,9 @@ form .field.saved .fa-xmark {
order: -1;
min-height: 80vh;
}

.buttons .field {
flex: 1 1 auto;
}

#model, #provider {
font-size: 14px;
padding: 6px;
}

.user-input .input-area {
padding: 8px;
}

textarea#message-input {
font-size: 14px;
}

.mobile-sidebar {
display: block;
position: fixed;
top: 10px;
left: 10px;
z-index: 1000;
}

.conversations {
position: fixed;
left: -100%;
top: 0;
bottom: 0;
transition: left 0.3s;
z-index: 999;
background: var(--bg-color);
}

.conversations.active {
left: 0;
}
}

/* Flexible form elements */
.user-input .input-area {
display: flex;
flex-wrap: wrap;
gap: 8px;
}

textarea {
max-width: 100%;
min-height: 50px;
resize: vertical;
}

/* Adaptive buttons */
button {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.file-label {
flex-shrink: 0;
}

/* Adaptive model menu */
#model, #provider {
max-width: 150px;
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 480px) {
.buttons .field {
flex: 1 1 100%;
}

#model, #provider {
max-width: 100%;
}

.toolbar {
flex-wrap: wrap;
gap: 5px;
}

.info .convo-title {
font-size: 12px;
}
Expand Down
14 changes: 3 additions & 11 deletions g4f/gui/client/static/js/chat.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -1651,8 +1651,10 @@ window.addEventListener('popstate', hide_sidebar, false);
sidebar_button.addEventListener("click", async () => {
if (sidebar.classList.contains("shown")) {
await hide_sidebar();
chat.classList.remove("hidden");
} else {
await show_menu();
chat.classList.add("hidden");
}
window.scrollTo(0, 0);
});
Expand Down Expand Up @@ -2096,7 +2098,7 @@ async function on_api() {
<span class="label">Providers API key</span>
<i class="fa-solid fa-chevron-down"></i>
</div>
<div class="collapsible-content hidden"></div>
<div class="collapsible-content api-key hidden"></div>
`;
settings.querySelector(".paper").appendChild(providersListContainer);

Expand Down Expand Up @@ -2739,13 +2741,3 @@ document.getElementById("showLog").addEventListener("click", ()=> {
settings.classList.add("hidden");
log_storage.scrollTop = log_storage.scrollHeight;
});

document.querySelector('.mobile-sidebar').addEventListener('click', function() {
document.querySelector('.conversations').classList.toggle('active');
});

document.addEventListener('click', function(e) {
if(!e.target.closest('.conversations') && !e.target.closest('.mobile-sidebar')) {
document.querySelector('.conversations').classList.remove('active');
}
});
6 changes: 3 additions & 3 deletions g4f/image/copy_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ async def copy_images(
) as session:
async def copy_image(image: str, target: str = None) -> str:
"""Process individual image and return its local URL"""
target_path = None
try:
target_path = target
if target_path is None:
# Generate filename components
file_hash = hashlib.sha256(image.encode()).hexdigest()[:16]
timestamp = int(time.time())
Expand All @@ -88,7 +88,7 @@ async def copy_image(image: str, target: str = None) -> str:
f"{extension}"
)
target_path = os.path.join(images_dir, filename)

try:
# Handle different image types
if image.startswith("data:"):
with open(target_path, "wb") as f:
Expand Down
2 changes: 1 addition & 1 deletion g4f/tools/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
from ..errors import MissingRequirementsError
from .. import debug

PLAIN_FILE_EXTENSIONS = ["txt", "xml", "json", "js", "har", "sh", "py", "php", "css", "yaml", "sql", "log", "csv", "twig", "md"]
PLAIN_FILE_EXTENSIONS = ["txt", "xml", "json", "js", "har", "sh", "py", "php", "css", "yaml", "sql", "log", "csv", "twig", "md", "arc"]
PLAIN_CACHE = "plain.cache"
DOWNLOADS_FILE = "downloads.json"
FILE_LIST = "files.txt"
Expand Down

0 comments on commit 292d5b6

Please sign in to comment.