Skip to content

Commit

Permalink
Merge pull request #77 from Suwayomi/main
Browse files Browse the repository at this point in the history
fix flashing on open in new tab && fix long press select in FF
  • Loading branch information
Robonau authored Nov 12, 2023
2 parents 35e82e3 + 91d7290 commit 6cf6a94
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
40 changes: 24 additions & 16 deletions src/lib/press.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,49 @@ interface Attributes {

export function longpress(node: HTMLElement, threshold = 500): ActionReturn<number, Attributes> {
const handle_mousedown = (ee: MouseEvent | TouchEvent) => {
const timeout = setTimeout(() => {
node.dispatchEvent(new CustomEvent('longpress'));
removeListners(node, move, cancel);
}, threshold);

let previousTouch: null | Touch = null;
if (ee instanceof TouchEvent) {
if (window.TouchEvent && ee instanceof TouchEvent) {
previousTouch = ee.touches[0];
}
const move = (e: MouseEvent | TouchEvent) => {
let [movementX, movementY] = [0, 0];
if (e instanceof TouchEvent) {
if (window.TouchEvent && e instanceof TouchEvent) {
const touch = e.touches[0];
if (previousTouch) {
movementX = touch.pageX - previousTouch.pageX;
movementY = touch.pageY - previousTouch.pageY;
}
previousTouch = touch;
} else {
} else if (e instanceof MouseEvent) {
movementX = e.movementX;
movementY = e.movementY;
}
const diff = Math.abs(movementX) + Math.abs(movementY);
if (diff > 20) cancel();
};

const timeout = setTimeout(() => {
node.dispatchEvent(new CustomEvent('longpress'));
removeListners(node, move, cancel);
}, threshold);

const cancel = () => {
clearTimeout(timeout);
removeListners(node, move, cancel);
};
addListners(node, move, cancel);
};

node.addEventListener('touchstart', handle_mousedown);
if (window.TouchEvent) {
node.addEventListener('touchstart', handle_mousedown);
}
node.addEventListener('mousedown', handle_mousedown);
return {
destroy: () => {
node.removeEventListener('mousedown', handle_mousedown);
node.removeEventListener('touchstart', handle_mousedown);
if (window.TouchEvent) {
node.removeEventListener('touchstart', handle_mousedown);
}
}
};
}
Expand All @@ -56,9 +60,11 @@ function addListners(
) {
node.addEventListener('mousemove', move);
node.addEventListener('mouseup', cancel);
node.addEventListener('touchend', cancel);
node.addEventListener('touchcancel', cancel);
node.addEventListener('touchmove', move);
if (window.TouchEvent) {
node.addEventListener('touchend', cancel);
node.addEventListener('touchcancel', cancel);
node.addEventListener('touchmove', move);
}
}

function removeListners(
Expand All @@ -68,7 +74,9 @@ function removeListners(
) {
node.removeEventListener('mousemove', move);
node.removeEventListener('mouseup', cancel);
node.removeEventListener('touchend', cancel);
node.removeEventListener('touchcancel', cancel);
node.removeEventListener('touchmove', move);
if (window.TouchEvent) {
node.removeEventListener('touchend', cancel);
node.removeEventListener('touchcancel', cancel);
node.removeEventListener('touchmove', move);
}
}
5 changes: 3 additions & 2 deletions src/lib/simpleStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function GlobalMeta() {

Meta.subscribe((e) => {
store.update((n) => {
const Ncopy = structuredClone(trueDefaults) as { [key: string]: unknown };
const Ncopy = structuredClone(get(store)) as { [key: string]: unknown };
(Object.keys(n) as (keyof globalMeta)[]).forEach((ee) => {
const tmp = e.data.metas?.nodes.find((k) => k.key.replace('VUI3_', '') === ee);
if (!tmp) return;
Expand All @@ -139,6 +139,7 @@ function GlobalMeta() {
});

async function set(val: globalMeta) {
console.log(val);
(Object.entries(val) as [keyof globalMeta, unknown][]).forEach(async (entry) => {
const value = JSON.stringify(entry[1]);
const key = `VUI3_${entry[0]}`;
Expand Down Expand Up @@ -204,7 +205,7 @@ export function MangaMeta(id: number) {

MMeta.subscribe((e) => {
store.update((n) => {
const Ncopy = structuredClone(get(Meta).mangaMetaDefaults) as { [key: string]: unknown };
const Ncopy = structuredClone(get(store)) as { [key: string]: unknown };
(Object.keys(n) as (keyof mangaMeta)[]).forEach((ee) => {
const tmp = e.data.manga?.meta.find((k) => k.key.replace('VUI3_', '') === ee);
if (!tmp) return;
Expand Down
42 changes: 22 additions & 20 deletions src/routes/(app)/(library)/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,7 @@
});
}
$: sortedMangas = filteredMangas?.sort((a, b) => {
let tru = true;
switch ($Meta.Sort) {
case sort.ID:
tru = a.id > b.id;
break;
case sort.Unread:
tru = a.unreadCount > b.unreadCount;
break;
case sort.Alphabetical:
tru = a.title > b.title;
break;
case sort['Last Read']:
tru = a.lastReadChapter?.lastReadAt > b.lastReadChapter?.lastReadAt;
break;
}
if ($Meta.Asc) tru = !tru;
return tru ? -1 : 1;
});
$: console.log($Meta);
$: filteredMangas = $mangas.data.category?.mangas.nodes.filter((ele) => {
if (!ele.inLibrary) return false;
Expand All @@ -114,6 +95,27 @@
return true;
});
$: sortedMangas = filteredMangas?.sort((a, b) => {
let tru = true;
switch ($Meta.Sort) {
case sort.ID:
tru = a.id > b.id;
break;
case sort.Unread:
tru = a.unreadCount > b.unreadCount;
break;
case sort.Alphabetical:
tru = a.title > b.title;
break;
case sort['Last Read']:
tru = a.lastReadChapter?.lastReadAt > b.lastReadChapter?.lastReadAt;
break;
}
if ($Meta.Asc) tru = !tru;
return tru ? -1 : 1;
});
function selectall() {
HelpSelectall(selectmode, selected, sortedMangas);
}
Expand Down

0 comments on commit 6cf6a94

Please sign in to comment.