about summary refs log tree commit diff
path: root/MatrixUtils.Web/Shared/MxcImage.razor
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Shared/MxcImage.razor')
-rw-r--r--MatrixUtils.Web/Shared/MxcImage.razor25
1 files changed, 20 insertions, 5 deletions
diff --git a/MatrixUtils.Web/Shared/MxcImage.razor b/MatrixUtils.Web/Shared/MxcImage.razor
index fb8c248..f31c19f 100644
--- a/MatrixUtils.Web/Shared/MxcImage.razor
+++ b/MatrixUtils.Web/Shared/MxcImage.razor
@@ -1,4 +1,4 @@
-<img class="@Class" src="@ResolvedUri" style="@Style"/>
+<img src="@ResolvedUri" style="@StyleString"/>
 @code {
     private string _mxcUri;
     private string _style;
@@ -13,9 +13,14 @@
             UriHasChanged(value);
         }
     }
+    [Parameter]
+    public bool Circular { get; set; }
     
-    //mxcuri binding
+    [Parameter]
+    public int? Width { get; set; }
     
+    [Parameter]
+    public int? Height { get; set; }
     
     [Parameter]
     public string Style {
@@ -36,8 +41,18 @@
         }
     }
 
+    private string StyleString => $"{Style} {(Circular ? "border-radius: 50%;" : "")} {(Width.HasValue ? $"width: {Width}px;" : "")} {(Height.HasValue ? $"height: {Height}px;" : "")}";
+    
+    private static readonly string Prefix = "mxc://";
+    private static readonly int PrefixLength = Prefix.Length;
+
     private async Task UriHasChanged(string value) {
-        var uri = value[5..].Split('/');
+        if (!value.StartsWith(Prefix)) {
+            Console.WriteLine($"UriHasChanged: {value} does not start with {Prefix}, passing as resolved URI!!!");
+            ResolvedUri = value;
+            return;
+        }
+        var uri = value[PrefixLength..].Split('/');
         Console.WriteLine($"UriHasChanged: {value} {uri[0]}");
         if (Homeserver is null) {
             Console.WriteLine($"Homeserver is null, creating new remotehomeserver for {uri[0]}");
@@ -47,7 +62,7 @@
         Console.WriteLine($"ResolvedUri: {ResolvedUri}");
     }
 
-    [Parameter]
-    public string Class { get; set; }
+    // [Parameter]
+    // public string Class { get; set; }
 
 }
\ No newline at end of file