Skip to content

Commit

Permalink
feat: refactor net status view (#222)
Browse files Browse the repository at this point in the history
* feat: refactor net status view

* chore: status => base_status
  • Loading branch information
GeopJr authored Apr 27, 2023
1 parent b95e860 commit 9f74fcb
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 53 deletions.
1 change: 1 addition & 0 deletions data/ui/views/base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<property name="child">
<object class="GtkSpinner" id="status_spinner">
<property name="height_request">32</property>
<property name="valign">center</property>
</object>
</property>
</object>
Expand Down
82 changes: 42 additions & 40 deletions src/Views/Base.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,46 @@ public class Tuba.Views.Base : Box {
[GtkChild] unowned Label status_message_label;
[GtkChild] unowned Spinner status_spinner;

public string state { get; set; default = "status"; }
public string status_title { get; set; default = STATUS_EMPTY; }
public string status_message { get; set; default = STATUS_EMPTY; }
public bool status_loading { get; set; default = false; }

construct {
build_actions ();
build_header ();
public class StatusMessage : Object {
public string title = STATUS_EMPTY;
public string? message = null;
public bool loading = false;
}

status_button.label = _("Reload");
bind_property ("state", states, "visible-child-name", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
target.set_string (src.get_string ());
if (src.get_string () != "status") status_spinner.spinning = false;
private StatusMessage? _base_status = null;
public StatusMessage? base_status {
get {
return _base_status;
}
set {
if (value == null) {
states.visible_child_name = "content";
status_spinner.spinning = false;
} else {
states.visible_child_name = "status";
if (value.loading) {
status_stack.visible_child_name = "spinner";
status_spinner.spinning = true;
} else {
status_stack.visible_child_name = "message";
status_spinner.spinning = false;

status_title_label.label = value.title;
if (value.message != null)
status_message_label.label = value.message;
}
}
_base_status = value;
}
}

return true;
});
bind_property ("status-loading", status_stack, "visible-child-name", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
target.set_string (src.get_boolean () ? "spinner" : "message");
status_spinner.spinning = src.get_boolean ();

return true;
});
bind_property ("status-message", status_message_label, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
var src_s = src.get_string ();
target.set_string (src_s);
status_message_label.visible = src_s != STATUS_EMPTY && src_s != "";
return true;
});
bind_property ("status-title", status_title_label, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
var src_s = src.get_string ();
target.set_string (src_s);
status_message = STATUS_EMPTY;
status_loading = src_s == "";
return true;
});
construct {
build_actions ();
build_header ();

notify["status-title"].connect (() => {
status_title_label.label = status_title;
status_message = STATUS_EMPTY;
});
status_button.label = _("Reload");
base_status = new StatusMessage () { loading = true };

notify["current"].connect (() => {
if (current)
Expand Down Expand Up @@ -106,7 +106,7 @@ public class Tuba.Views.Base : Box {
}

public virtual void clear () {
state = "status";
base_status = null;
}

public virtual void on_shown () {
Expand All @@ -121,11 +121,13 @@ public class Tuba.Views.Base : Box {
public virtual void on_content_changed () {}

public virtual void on_error (int32 code, string reason) {
status_title = _("An Error Occurred");
status_message = reason;
base_status = new StatusMessage () {
title = _("An Error Occurred"),
message = reason
};

status_button.visible = true;
status_button.sensitive = true;
state = "status";
}

[GtkCallback]
Expand Down
5 changes: 2 additions & 3 deletions src/Views/ContentBase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ public class Tuba.Views.ContentBase : Views.Base {

public override void on_content_changed () {
if (empty) {
status_title = STATUS_EMPTY;
state = "status";
base_status = new StatusMessage ();
}
else {
state = "content";
base_status = null;
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/Views/Search.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ public class Tuba.Views.Search : Views.TabbedBase {
query = entry.text.chug ().chomp ();
if (query == "") {
clear ();
state = "status";
status_title = _("Enter Query");
base_status = new StatusMessage () { title = _("Enter Query") };
return;
}

clear ();
state = "status";
status_loading = true;
base_status = new StatusMessage () { loading = true };
API.SearchResults.request.begin (query, accounts.active, (obj, res) => {
try {
var results = API.SearchResults.request.end (res);
Expand Down Expand Up @@ -99,7 +97,7 @@ public class Tuba.Views.Search : Views.TabbedBase {
});
}

status_title = STATUS_EMPTY;
base_status = new StatusMessage ();

on_content_changed ();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Views/TabbedBase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Tuba.Views.TabbedBase : Views.Base {
Views.Base? last_view = null;

construct {
state = "content";
base_status = null;

var states_box = states.get_parent () as Box;
if (states_box != null)
Expand Down Expand Up @@ -100,7 +100,7 @@ public class Tuba.Views.TabbedBase : Views.Base {

tab.on_content_changed ();
});
state = "content";
base_status = null;

// if (empty) {
// state = "status";
Expand Down
2 changes: 1 addition & 1 deletion src/Views/Thread.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Tuba.Views.Thread : Views.ContentBase, AccountHolder {
public Thread (API.Status status) {
Object (
root_status: status,
status_loading: true,
base_status: new StatusMessage () { loading = true },
label: _("Conversation")
);
construct_account_holder ();
Expand Down
4 changes: 2 additions & 2 deletions src/Views/Timeline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class Tuba.Views.Timeline : AccountHolder, Streamable, Views.ContentBase
}

public virtual void on_request_finish () {
status_loading = false;
base_status = null;
base.on_bottom_reached ();
}

Expand Down Expand Up @@ -111,7 +111,7 @@ public class Tuba.Views.Timeline : AccountHolder, Streamable, Views.ContentBase
scrolled.vadjustment.value = 0;
status_button.sensitive = false;
clear ();
status_loading = true;
base_status = new StatusMessage () { loading = true };
GLib.Idle.add (request);
}

Expand Down

0 comments on commit 9f74fcb

Please sign in to comment.