Customize home screen (#250)
* Customize home screen * remove logs * Lint fix * move func * Fix for checklist * Fix save state * open api * Fix spec * Changelog * Add TODO * Button size --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
e7324495fe
commit
fd7bdde733
21 files changed
+638
-16
No files matched your search
@@ -13,6 +13,12 @@ export class PlayletApi {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
// Home layout is the home layout file, but with the user's preferences applied.
|
||||
static async getHomeLayout() {
|
||||
const response = await fetch(`${PlayletApi.host()}/api/home-layout`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async getHomeLayoutFile() {
|
||||
const response = await fetch(`${PlayletApi.host()}/config/default_home_layout.yaml`);
|
||||
return await response.json();
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<script lang="ts">
|
||||
import VideoListRow from "lib/VideoFeed/VideoListRow.svelte";
|
||||
import { homeLayoutFileStore } from "lib/Stores";
|
||||
import { homeLayoutStore } from "lib/Stores";
|
||||
|
||||
export let visibility: boolean;
|
||||
</script>
|
||||
|
||||
<div class={visibility ? "" : "hidden"}>
|
||||
<!-- TODO:P0 Handle authenticated feed when not logged in -->
|
||||
{#each $homeLayoutFileStore as feed}
|
||||
{#each $homeLayoutStore as feed}
|
||||
<VideoListRow {feed} />
|
||||
{/each}
|
||||
</div>
|
||||
@@ -0,0 +1,144 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
homeLayoutFileStore,
|
||||
homeLayoutStore,
|
||||
userPreferencesStore,
|
||||
} from "lib/Stores";
|
||||
import ArrowUpIcon from "assets/remote-control/arrow-up.svg.svelte";
|
||||
import ArrowDownIcon from "assets/remote-control/arrow-down.svg.svelte";
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
|
||||
export let displayText: string = "";
|
||||
// svelte-ignore unused-export-let
|
||||
export let key: string = "";
|
||||
export let description: string = "";
|
||||
export let level: number = 0;
|
||||
|
||||
let value;
|
||||
let originalValue;
|
||||
let homeLayout;
|
||||
userPreferencesStore.subscribe((userPreferences) => {
|
||||
originalValue = userPreferences[key];
|
||||
});
|
||||
|
||||
homeLayoutFileStore.subscribe((value) => {
|
||||
homeLayout = value.reduce((acc, cur) => {
|
||||
acc[cur.id] = cur;
|
||||
return acc;
|
||||
}, {});
|
||||
});
|
||||
|
||||
let modal;
|
||||
|
||||
async function openHomeScreenEditor() {
|
||||
value = JSON.parse(JSON.stringify(originalValue));
|
||||
modal.showModal();
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (key !== "" && value) {
|
||||
await PlayletApi.saveUserPreference(key, value);
|
||||
|
||||
const refreshUserPrefrences = PlayletApi.getUserPreferences();
|
||||
refreshUserPrefrences.then((value) => {
|
||||
userPreferencesStore.set(value);
|
||||
});
|
||||
|
||||
const refreshHomeLayout = PlayletApi.getHomeLayout();
|
||||
refreshHomeLayout.then((value) => {
|
||||
homeLayoutStore.set(value);
|
||||
});
|
||||
|
||||
await Promise.all([refreshUserPrefrences, refreshHomeLayout]);
|
||||
}
|
||||
}
|
||||
|
||||
function onClose() {
|
||||
// Reset value to original value to avoid weird animation on show
|
||||
value = JSON.parse(JSON.stringify(originalValue));
|
||||
}
|
||||
|
||||
function moveUp(index) {
|
||||
if (index > 0) {
|
||||
const updatedValue = [...value];
|
||||
[updatedValue[index - 1], updatedValue[index]] = [
|
||||
updatedValue[index],
|
||||
updatedValue[index - 1],
|
||||
];
|
||||
value = updatedValue;
|
||||
}
|
||||
}
|
||||
|
||||
function moveDown(index) {
|
||||
if (index < value.length - 1) {
|
||||
const updatedValue = [...value];
|
||||
[updatedValue[index], updatedValue[index + 1]] = [
|
||||
updatedValue[index + 1],
|
||||
updatedValue[index],
|
||||
];
|
||||
value = updatedValue;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="m-5">
|
||||
<div class={textSizes[level]}>{displayText}</div>
|
||||
<div class="text-xs text-gray-500">{@html description}</div>
|
||||
<button class="btn m-1" on:click={openHomeScreenEditor}
|
||||
>Edit home screen</button
|
||||
>
|
||||
</div>
|
||||
|
||||
<dialog bind:this={modal} on:close={onClose} class="modal">
|
||||
<div class="modal-box bg-base-100">
|
||||
{#if value && homeLayout}
|
||||
<table class="w-full">
|
||||
{#each value as item, i (i)}
|
||||
<tr>
|
||||
<td>
|
||||
<div class="tooltip" data-tip="Move up">
|
||||
<button
|
||||
class="btn btn-outline btn-sm"
|
||||
on:click={() => moveUp(i)}
|
||||
disabled={i === 0}
|
||||
>
|
||||
<ArrowUpIcon />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<label class="label p-0 cursor-pointer">
|
||||
<div class="label-text">{homeLayout[item.id].title}</div>
|
||||
<input
|
||||
type="checkbox"
|
||||
name={item.id}
|
||||
bind:checked={item.enabled}
|
||||
class="toggle toggle-primary"
|
||||
/>
|
||||
</label>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<div class="tooltip" data-tip="Move down">
|
||||
<button
|
||||
class="btn btn-outline btn-sm m-2"
|
||||
on:click={() => moveDown(i)}
|
||||
disabled={i === value.length - 1}
|
||||
>
|
||||
<ArrowDownIcon />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</table>
|
||||
<form method="dialog" class="flex justify-center">
|
||||
<button class="btn btn-primary" on:click={save}>Save</button>
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>Close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import BooleanControl from "lib/Screens/Settings/SettingControls/BooleanControl.svelte";
|
||||
import ClearSearchHistoryControl from "lib/Screens/Settings/SettingControls/ClearSearchHistoryControl.svelte";
|
||||
import EditHomeScreenControl from "lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte";
|
||||
import RadioControl from "lib/Screens/Settings/SettingControls/RadioControl.svelte";
|
||||
import StringControl from "lib/Screens/Settings/SettingControls/StringControl.svelte";
|
||||
|
||||
@@ -23,6 +24,7 @@
|
||||
|
||||
const customComponents = {
|
||||
ClearSearchHistoryControl,
|
||||
EditHomeScreenControl,
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ export const userPreferencesStore = writable({} as any);
|
||||
|
||||
export const invidiousVideoApiStore = writable({} as any);
|
||||
|
||||
export const homeLayoutStore = writable([] as any);
|
||||
|
||||
export const homeLayoutFileStore = writable([] as any);
|
||||
|
||||
export const bookmarksStore = writable([] as any);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
// TODO:P1 figure out why some uncached feeds (e.g. channels/ucid/videos) get hit twice
|
||||
export let feed: any = undefined;
|
||||
export let videos = [];
|
||||
let videos = [];
|
||||
|
||||
enum FeedLoadState {
|
||||
None,
|
||||
@@ -28,6 +28,8 @@
|
||||
let scrollStart = 0;
|
||||
let scrollEnd = 0;
|
||||
|
||||
let loadDataTask = undefined;
|
||||
|
||||
// w-80|w-60 p-2: 320px|240px + 16px padding on each side
|
||||
const videoItemWidth = 320 + 16 * 2;
|
||||
const channelItemWidth = 240 + 16 * 2;
|
||||
@@ -42,6 +44,18 @@
|
||||
{ threshold: [0] }
|
||||
);
|
||||
|
||||
$: {
|
||||
if (feed) {
|
||||
feedSourcesIndex = 0;
|
||||
feedLoadState = FeedLoadState.None;
|
||||
videos = [];
|
||||
itemWidths = [];
|
||||
scrollStart = 0;
|
||||
scrollEnd = 0;
|
||||
loadDataTask = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if (
|
||||
carouselElement &&
|
||||
@@ -112,8 +126,6 @@
|
||||
loadDataTask = undefined;
|
||||
}
|
||||
|
||||
let loadDataTask;
|
||||
|
||||
async function loadData() {
|
||||
feedLoadState = FeedLoadState.Loading;
|
||||
let totalFetchedItems = 0;
|
||||
|
||||
Reference in new issue
Block a user