mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-11 17:42:48 +00:00
feat: add favorites - update dependencies
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { SoundType } from '../components/sound-list/sound-list';
|
||||
import { ISound } from '../model';
|
||||
import { ISound, SoundListType, SoundType } from '../model';
|
||||
import { axios } from './axios.service';
|
||||
|
||||
const playSound = (sound: SoundType): Promise<any> => {
|
||||
@@ -11,7 +10,15 @@ const getSounds = async (): Promise<ISound[]> => {
|
||||
return res.data.data;
|
||||
};
|
||||
|
||||
export const playAudioInBrowser = (sound: SoundType, type: SoundListType) => {
|
||||
const t = type === 'favorites' ? 'sounds' : type;
|
||||
const url = `/public/${t.toLowerCase()}/` + sound.name + '.' + sound.extension;
|
||||
const audio = new Audio(url);
|
||||
audio.play();
|
||||
};
|
||||
|
||||
export const SoundService = {
|
||||
getSounds,
|
||||
playSound,
|
||||
playAudioInBrowser,
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { SoundType } from '../model';
|
||||
|
||||
const clear = () => {
|
||||
localStorage.clear();
|
||||
};
|
||||
@@ -10,8 +12,19 @@ const getJWT = (): string | null => {
|
||||
return localStorage.getItem('jwt');
|
||||
};
|
||||
|
||||
const getFavorites = (): SoundType[] => {
|
||||
const f = localStorage.getItem('favorites');
|
||||
return f ? JSON.parse(f) : [];
|
||||
};
|
||||
|
||||
const setFavorites = (f: SoundType[]): void => {
|
||||
localStorage.setItem('favorites', JSON.stringify(f));
|
||||
};
|
||||
|
||||
export const StorageService = {
|
||||
clear,
|
||||
getJWT,
|
||||
setJWT,
|
||||
getFavorites,
|
||||
setFavorites,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user