diff --git a/app/components/DiscoverTracks/SubmitButtion.tsx b/app/components/DiscoverTracks/SubmitButtion.tsx index 974344f..b64b715 100644 --- a/app/components/DiscoverTracks/SubmitButtion.tsx +++ b/app/components/DiscoverTracks/SubmitButtion.tsx @@ -1,7 +1,6 @@ 'use client'; import { - addToUrl, extractPlaylistId, getAllTracks, getEveryAlbum, @@ -25,6 +24,7 @@ import { useLoading } from '@/app/context/loadingContext'; import { useOptions } from '@/app/context/optionsContext'; import { useType } from '@/app/context/DiscoverTracks/typeContext'; import { toast } from 'react-toastify'; +import { addToUrl } from '@/app/lib/clientUtils'; const API_KEY = process.env.NEXT_PUBLIC_API_KEY; const genAI = new GoogleGenerativeAI(API_KEY as string); diff --git a/app/components/ResultLink.tsx b/app/components/ResultLink.tsx index 80b3078..f488cd9 100644 --- a/app/components/ResultLink.tsx +++ b/app/components/ResultLink.tsx @@ -3,9 +3,10 @@ import React, { useEffect } from 'react'; import OpenOnSpotify from './OpenOnSpotify'; -import { addPlaylistFullLinkFromID, getFromUrl } from '../lib/utils'; +import { addPlaylistFullLinkFromID } from '../lib/utils'; import { useGeneralState } from '@/app/context/generalStateContext'; import { useLoading } from '@/app/context/loadingContext'; +import { getFromUrl } from '../lib/clientUtils'; const ResultLink = () => { const { loading } = useLoading(); diff --git a/app/lib/clientUtils.ts b/app/lib/clientUtils.ts new file mode 100644 index 0000000..1059af7 --- /dev/null +++ b/app/lib/clientUtils.ts @@ -0,0 +1,25 @@ +'use client'; + +export const addToUrl = (key: string, value: string) => { + try { + const searchParams = new URLSearchParams(window.location.search); + searchParams.set(key, value); + const newUrl = `${window.location.pathname}?${searchParams.toString()}`; + window.history.pushState({}, '', newUrl); + } catch (error) { + console.log('Error adding to url', error); + } +}; + +export const copyToClipboard = async (textToCopy: string) => { + if ('clipboard' in navigator) { + return await navigator.clipboard.writeText(textToCopy); + } else { + return document.execCommand('copy', true, textToCopy); + } +}; + +export const getFromUrl = (key: string) => { + const searchParams = new URLSearchParams(window.location.search); + return searchParams.get(key); +}; diff --git a/app/lib/utils.ts b/app/lib/utils.ts index d379a8e..febd0c3 100644 --- a/app/lib/utils.ts +++ b/app/lib/utils.ts @@ -90,29 +90,8 @@ export const convertToSubArray = (albums: string[]) => { return subArrays; }; -export const copyToClipboard = async (textToCopy: string) => { - if ('clipboard' in navigator) { - return await navigator.clipboard.writeText(textToCopy); - } else { - return document.execCommand('copy', true, textToCopy); - } -}; -export const addToUrl = (key: string, value: string) => { - try { - const searchParams = new URLSearchParams(window.location.search); - searchParams.set(key, value); - const newUrl = `${window.location.pathname}?${searchParams.toString()}`; - window.history.pushState({}, '', newUrl); - } catch (error) { - console.log('Error adding to url', error); - } -}; -export const getFromUrl = (key: string) => { - const searchParams = new URLSearchParams(window.location.search); - return searchParams.get(key); -}; export const formatDate = (date: Date) => { const day = String(date.getDate()).padStart(2, '0');