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 2 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
22 changes: 22 additions & 0 deletions daras_ai_v2/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.utils import timezone
from datetime import timedelta


def get_relative_time(timestamp):
diff = timezone.now() - timestamp
seconds = diff.total_seconds()

if seconds < 2:
anish-work marked this conversation as resolved.
Show resolved Hide resolved
return "Just now"
if seconds < timedelta(minutes=1).total_seconds():
return f"{int(seconds)}s ago"
elif seconds < timedelta(hours=1).total_seconds():
return f"{int(seconds/timedelta(minutes=1).total_seconds())}m ago"
elif seconds < timedelta(days=1).total_seconds():
return f"{int(seconds/timedelta(hours=1).total_seconds())}h ago"
elif seconds < timedelta(days=30).total_seconds():
return f"{int(seconds/timedelta(days=1).total_seconds())}d ago"
elif seconds < timedelta(days=365).total_seconds():
return f"{int(seconds/timedelta(days=30).total_seconds())}mo ago"
else:
return f"{int(seconds/timedelta(days=365).total_seconds())}y ago"
Loading