Add minial animations to Ui
This commit is contained in:
parent
f453ff1a16
commit
2b03c39dfe
@ -107,6 +107,10 @@ func loadAlbumCover(albumId string) {
|
|||||||
|
|
||||||
// Tries to load the album cover
|
// Tries to load the album cover
|
||||||
func (a *App) GetAlbumCover(albumId string) ([]byte, error) {
|
func (a *App) GetAlbumCover(albumId string) ([]byte, error) {
|
||||||
|
if albumId == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
cacheMutex.Lock()
|
cacheMutex.Lock()
|
||||||
coverInfo, ok := albumCoverCacheInfo[albumId]
|
coverInfo, ok := albumCoverCacheInfo[albumId]
|
||||||
cacheMutex.Unlock()
|
cacheMutex.Unlock()
|
||||||
|
@ -1,19 +1,33 @@
|
|||||||
import { For, createMemo, createResource, createSignal, onMount } from "solid-js";
|
import { For, Show, createEffect, createMemo, createResource, createSignal, onCleanup, onMount } from "solid-js";
|
||||||
import { GetAlbumCover, GetRandomAlbums } from "../../wailsjs/go/main/App";
|
import { GetAlbumCover, GetRandomAlbums, LoadRandomAlbums } from "../../wailsjs/go/main/App";
|
||||||
import { main } from "../../wailsjs/go/models";
|
import { main } from "../../wailsjs/go/models";
|
||||||
|
|
||||||
export function Home() {
|
export function Home() {
|
||||||
const [hidden, setHidden] = createSignal(true);
|
const [hidden, setHidden] = createSignal(true);
|
||||||
const [albums] = createResource(GetRandomAlbums);
|
const [albums, {mutate, refetch}] = createResource<Array<main.Album | null>>(GetRandomAlbums);
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Fade in the UI
|
// Fade in the UI
|
||||||
setTimeout(() => setHidden(false), 150);
|
setTimeout(() => setHidden(false), 150);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const reload = () => {
|
||||||
|
LoadRandomAlbums();
|
||||||
|
mutate((new Array(20)).map(() => null));
|
||||||
|
setTimeout(refetch, 100);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={`min-h-screen ${hidden() ? "opacity-0" : "opacity-100"} transition-opacity`}>
|
<div class={`min-h-screen ${hidden() ? "opacity-0" : "opacity-100"} transition-opacity`}>
|
||||||
<h1 class="font-black text-2xl pt-6 pb-4 pl-2">Random albums</h1>
|
<h1 class="font-black text-2xl pt-6 pb-4 pl-2">
|
||||||
|
Random albums
|
||||||
|
<button
|
||||||
|
class="text-xs font-normal mx-1 p-1 rounded underline hover:bg-zinc-900"
|
||||||
|
onClick={reload}
|
||||||
|
>
|
||||||
|
Reload
|
||||||
|
</button>
|
||||||
|
</h1>
|
||||||
<div class="pb-4 overflow-scroll whitespace-nowrap">
|
<div class="pb-4 overflow-scroll whitespace-nowrap">
|
||||||
<For each={albums()}>
|
<For each={albums()}>
|
||||||
{(album) => <Album album={album} />}
|
{(album) => <Album album={album} />}
|
||||||
@ -23,8 +37,17 @@ export function Home() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Album(props: { album: main.Album }) {
|
function Album(props: { album: main.Album | null }) {
|
||||||
const [coverBytes] = createResource(async() => await GetAlbumCover(props.album.id));
|
const [coverBytes, {mutate, refetch}] = createResource<Array<number> | null>(async() => GetAlbumCover(props.album?.id ?? ""));
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
if (!props.album) {
|
||||||
|
mutate(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
refetch();
|
||||||
|
});
|
||||||
|
|
||||||
const base64Image = createMemo(() => {
|
const base64Image = createMemo(() => {
|
||||||
if (coverBytes.state !== "ready") return "";
|
if (coverBytes.state !== "ready") return "";
|
||||||
@ -34,20 +57,27 @@ function Album(props: { album: main.Album }) {
|
|||||||
return `data:;base64,${bytes}`;
|
return `data:;base64,${bytes}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isNull = createMemo(() => !props.album);
|
||||||
|
const opacity = createMemo(() => `${isNull() ? "opacity-0" : "opacity-100"} transition-opacity`);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="inline-block mx-2 p-1 w-32 rounded bg-zinc-900">
|
<div class="inline-block mx-2 p-1 w-32 rounded bg-zinc-900">
|
||||||
<img
|
<Show when={isNull()}>
|
||||||
class={`inline-block rounded w-30 h-30 min-w-30 min-h-30 transition-opacity ${coverBytes.state === "ready" ? "opacity-100" : "opacity-0"}`}
|
<div class="w-30 h-30" />
|
||||||
src={base64Image()}
|
</Show>
|
||||||
alt=""
|
<Show when={!isNull()}>
|
||||||
/>
|
<img
|
||||||
|
class={`inline-block rounded w-30 h-30 transition-opacity ${coverBytes.state === "ready" ? "opacity-100" : "opacity-0"}`}
|
||||||
|
src={base64Image()}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
</Show>
|
||||||
|
|
||||||
<br />
|
<div class={`text-sm overflow-hidden overflow-ellipsis pt-1 ${opacity()}`}>
|
||||||
<div class="text-sm overflow-hidden overflow-ellipsis pt-1">
|
{props.album?.name ?? "..."}
|
||||||
{props.album.name}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="text-xs overflow-hidden overflow-ellipsis opacity-50">
|
<div class={`text-xs overflow-hidden overflow-ellipsis ${opacity()}`}>
|
||||||
{props.album.albumArtist}
|
{props.album?.albumArtist ?? "..."}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
2
frontend/wailsjs/go/main/App.d.ts
vendored
2
frontend/wailsjs/go/main/App.d.ts
vendored
@ -8,4 +8,6 @@ export function GetRandomAlbums():Promise<Array<main.Album>>;
|
|||||||
|
|
||||||
export function Greet(arg1:string):Promise<string>;
|
export function Greet(arg1:string):Promise<string>;
|
||||||
|
|
||||||
|
export function LoadRandomAlbums():Promise<void>;
|
||||||
|
|
||||||
export function Login(arg1:string,arg2:string,arg3:string):Promise<boolean>;
|
export function Login(arg1:string,arg2:string,arg3:string):Promise<boolean>;
|
||||||
|
@ -14,6 +14,10 @@ export function Greet(arg1) {
|
|||||||
return window['go']['main']['App']['Greet'](arg1);
|
return window['go']['main']['App']['Greet'](arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function LoadRandomAlbums() {
|
||||||
|
return window['go']['main']['App']['LoadRandomAlbums']();
|
||||||
|
}
|
||||||
|
|
||||||
export function Login(arg1, arg2, arg3) {
|
export function Login(arg1, arg2, arg3) {
|
||||||
return window['go']['main']['App']['Login'](arg1, arg2, arg3);
|
return window['go']['main']['App']['Login'](arg1, arg2, arg3);
|
||||||
}
|
}
|
||||||
|
12
session.go
12
session.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
@ -55,7 +56,6 @@ func (a *App) Login(server, username, password string) (bool, error) {
|
|||||||
// Set global session
|
// Set global session
|
||||||
LoggedUser = successData
|
LoggedUser = successData
|
||||||
// Begin to load the list of albums on the background
|
// Begin to load the list of albums on the background
|
||||||
randomAlbumWaitGroup.Add(1)
|
|
||||||
go loadAlbums(server)
|
go loadAlbums(server)
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -68,6 +68,11 @@ func (a *App) Login(server, username, password string) (bool, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Triggers a reload of random albums
|
||||||
|
func (a *App) LoadRandomAlbums() {
|
||||||
|
go loadAlbums(serverUrl)
|
||||||
|
}
|
||||||
|
|
||||||
// Waits for the random albums to be loaded, and returns them.
|
// Waits for the random albums to be loaded, and returns them.
|
||||||
// This function assumes that the random albums are being loaded in the background.
|
// This function assumes that the random albums are being loaded in the background.
|
||||||
func (a *App) GetRandomAlbums() ([]Album, error) {
|
func (a *App) GetRandomAlbums() ([]Album, error) {
|
||||||
@ -80,9 +85,12 @@ func (a *App) GetRandomAlbums() ([]Album, error) {
|
|||||||
|
|
||||||
// Loads a list of random albums from the server.
|
// Loads a list of random albums from the server.
|
||||||
func loadAlbums(serverUrl string) {
|
func loadAlbums(serverUrl string) {
|
||||||
|
randomAlbumWaitGroup.Add(1)
|
||||||
defer randomAlbumWaitGroup.Done()
|
defer randomAlbumWaitGroup.Done()
|
||||||
|
|
||||||
log.Print("begin loadAlbums")
|
log.Print("begin loadAlbums")
|
||||||
client := resty.New()
|
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
var errorData AuthError
|
var errorData AuthError
|
||||||
response, err := client.R().
|
response, err := client.R().
|
||||||
|
Loading…
Reference in New Issue
Block a user