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

show last saved time #559

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 23 additions & 6 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from routers.root import RecipeTabs
from workspaces.models import Workspace, WorkspaceMembership
from workspaces.widgets import get_current_workspace, set_current_workspace
from daras_ai_v2.utils import get_relative_time

DEFAULT_META_IMG = (
# Small
Expand Down Expand Up @@ -345,12 +346,24 @@ def render(self):

header_placeholder = gui.div()
gui.newline()

with gui.nav_tabs():
for tab in self.get_tabs():
url = self.current_app_url(tab)
with gui.nav_item(url, active=tab == self.tab):
gui.html(tab.title)
with gui.div(className="position-relative"):
with gui.nav_tabs():
for tab in self.get_tabs():
url = self.current_app_url(tab)
with gui.nav_item(url, active=tab == self.tab):
gui.html(tab.title)

if self.current_pr and not self.current_pr.is_root():
with gui.div(
className="container-margin-reset d-none d-md-block",
style=dict(
position="absolute",
top="50%",
right="0",
transform="translateY(-50%)",
),
):
self._render_saved_timestamp(self.current_pr)
with gui.nav_tab_content():
self.render_selected_tab()

Expand Down Expand Up @@ -467,6 +480,10 @@ def _render_unpublished_changes_indicator(self):
):
gui.html("Unpublished changes")

def _render_saved_timestamp(self, pr: PublishedRun):
with gui.tag("span", className="text-muted"):
gui.write(f"{get_relative_time(pr.updated_at)}")

def _render_options_button_with_dialog(self):
ref = gui.use_alert_dialog(key="options-modal")
if gui.button(label=icons.more_options, className="mb-0", type="tertiary"):
Expand Down
19 changes: 19 additions & 0 deletions daras_ai_v2/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.utils import timezone
from datetime import timedelta, datetime

THRESHOLDS = [
(timedelta(days=365), "y"),
(timedelta(days=30), "mo"),
(timedelta(days=1), "d"),
(timedelta(hours=1), "h"),
(timedelta(minutes=1), "m"),
(timedelta(seconds=3), "s"),
]


def get_relative_time(timestamp: datetime) -> str:
diff = timezone.now() - timestamp
for threshold, unit in THRESHOLDS:
if diff >= threshold:
return f"{round(diff / threshold)}{unit} ago"
Comment on lines +17 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: using round() instead of int() could change behavior - e.g. 1.6 days will now show as 2d instead of 1d

return "Just now"
Loading