Search Improvements

This commit is contained in:
Shiny Nematoda 2022-05-03 19:17:48 +05:30
parent 51c56abe16
commit 19fc65e6c0
19 changed files with 545 additions and 404 deletions

View file

@ -1,16 +1,16 @@
const c = [
"linear-gradient(45deg, #88c0d0, #5e81ac)",
"linear-gradient(45deg, #5e81ac, #b48ead)",
"linear-gradient(45deg, #a3be8c, #88c0d0)",
"linear-gradient(45deg, #ebcb8b, #a3be8c)",
"linear-gradient(45deg, #d08770, #bf616a)"
'linear-gradient(45deg, #88c0d0, #5e81ac)',
'linear-gradient(45deg, #5e81ac, #b48ead)',
'linear-gradient(45deg, #a3be8c, #88c0d0)',
'linear-gradient(45deg, #ebcb8b, #a3be8c)',
'linear-gradient(45deg, #d08770, #bf616a)',
];
export function useColors() {
return c
return c;
}
export function useRand() {
const i = Math.floor(Math.random() * c.length);
return c[i]
}
const i = Math.floor(Math.random() * c.length);
return c[i];
}

View file

@ -1,98 +1,116 @@
export function useSetupDB() {
if ('indexedDB' in window) {
const req = indexedDB.open('hyperpipedb', 1);
req.onupgradeneeded = (e) => {
const db = e.target.result;
console.log(db);
if (!db.objectStoreNames.contains('playlist')) {
const store = db.createObjectStore('playlist', { keyPath: 'name' });
store.createIndex('urls', 'urls', { unique: false });
}
};
req.onerror = (e) => {
console.log('Please let me use indexedDB!!');
console.log(e);
};
req.onsuccess = (e) => {
window.db = e.target.result;
};
}
}
export function useUpdatePlaylist(key, obj, cb = () => null) {
if (window.db && key) {
const store = window.db.transaction(['playlist'], "readwrite").objectStore('playlist'),
req = store.get(key);
if (window.db && key) {
const store = window.db
.transaction(['playlist'], 'readwrite')
.objectStore('playlist'),
req = store.get(key);
req.onerror = (e) => {
console.log('Error!!', e)
}
req.onerror = (e) => {
console.log('Error!!', e);
};
req.onsuccess = e => {
const itm = e.target.result;
if (itm) {
itm.urls.push(obj)
store.put(itm)
cb(true)
}
}
} else alert('No indexedDB Created')
req.onsuccess = (e) => {
const itm = e.target.result;
if (itm) {
itm.urls.push(obj);
store.put(itm);
cb(true);
}
};
} else alert('No indexedDB Created');
}
export function useCreatePlaylist(key, obj, cb = () => null ) {
if (window.db && key && obj) {
const store = window.db.transaction(['playlist'], "readwrite").objectStore('playlist'),
req = store.get(key);
export function useCreatePlaylist(key, obj, cb = () => null) {
if (window.db && key && obj) {
const store = window.db
.transaction(['playlist'], 'readwrite')
.objectStore('playlist'),
req = store.get(key);
req.onerror = (e) => {
console.log('Error!!', e)
}
req.onerror = (e) => {
console.log('Error!!', e);
};
req.onsuccess = (e) => {
const res = e.target.result;
req.onsuccess = (e) => {
const res = e.target.result;
if (!res) {
if (!res) {
store.add({
name: key,
urls: obj,
});
store.add({
name: key, urls: obj
});
cb(res);
} else {
console.log(e.target.result);
alert(`Error: Playlist with name ${key} exists`)
}
}
} else alert('No indexedDB Created')
cb(res);
} else {
console.log(e.target.result);
alert(`Error: Playlist with name ${key} exists`);
}
};
} else alert('No indexedDB Created');
}
export function useGetPlaylist(key, cb = () => null ) {
export function useGetPlaylist(key, cb = () => null) {
if (window.db && key) {
const store = window.db.transaction(['playlist']).objectStore('playlist'),
req = store.get(key);
if (window.db && key) {
const store = window.db.transaction(['playlist']).objectStore('playlist'),
req = store.get(key);
req.onerror = (e) => {
console.log('Error!!', e);
};
req.onerror = (e) => {
console.log('Error!!', e)
}
req.onsuccess = (e) => {
const res = e.target.result;
req.onsuccess = e => {
const res = e.target.result;
if (res) {
cb(res)
}
}
} else alert('No indexedDB Created')
if (res) {
cb(res);
}
};
} else alert('No indexedDB Created');
}
export function useListPlaylists(cb = () => null) {
if (window.db) {
if (window.db) {
let pls = [];
let pls = [];
const store = window.db.transaction(['playlist']).objectStore('playlist'),
cursor = store.openCursor();
const store = window.db.transaction(['playlist']).objectStore('playlist'),
cursor = store.openCursor();
cursor.onsuccess = (e) => {
const pl = e.target.result;
cursor.onsuccess = (e) => {
const pl = e.target.result;
if (pl) {
pls.push(pl.value)
pl.continue()
} else {
cb(pls)
}
}
}
}
if (pl) {
pls.push(pl.value);
pl.continue();
} else {
cb(pls);
}
};
}
}

View file

@ -1,8 +1,8 @@
export function usePrefs(key) {
if (localStorage) {
if (localStorage.get(key)) return true
else return false
} else return false
if (localStorage) {
if (localStorage.get(key)) return true;
else return false;
} else return false;
}
export function useLazyLoad() {
@ -30,4 +30,4 @@ export function useLazyLoad() {
} else {
console.log('Failed');
}
}
}