Skip to content

Commit

Permalink
Re-organise imports and variables across the app
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-nexus committed Jul 17, 2024
1 parent 52eb80e commit 859f493
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/app/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import Player from "@/components/Player"
import Toast from "@/components/Toast.tsx"
import { getLanguageName } from "@/helpers/getLanguageName"
import { useFetchArticle } from "@/helpers/handleArticle/useFetchArticle"
import { isLocalStorageSupported } from "@/helpers/isLocalStorageSupported"
import { useChooseBestVoice } from "@/helpers/setUpWebSpeech/useChooseBestVoice"
import { useArticleStore } from "@/stores/useArticleStore"
import { useGenericStore } from "@/stores/useGenericStore"
import { useEffect } from "react"
import { useChooseBestVoice } from "@/helpers/setUpWebSpeech/useChooseBestVoice"
import { isLocalStorageSupported } from "@/helpers/isLocalStorageSupported"
import { usePlayerStore } from "@/stores/usePlayerStore"
import { useEffect } from "react"

export type ToastType = "language-detected" | "fetch-message"

Expand Down
14 changes: 7 additions & 7 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use client"

import { Figtree } from "next/font/google"
import 'material-icons/iconfont/filled.css'
import "animate.css";
import "./globals.css"
import Head from "@/components/Head"
import Head from "@/components/Head";
import { useIsPwaInstallable } from "@/helpers/handlePwaLifeCycle/useIsPwaInstallable";
import { usePopulateVoices } from "@/helpers/setUpWebSpeech/usePopulateVoices";
import { useIsMobileOrTabletOnClient } from "@/helpers/useIsMobileOrTabletOnClient";
import { useEffect } from "react";
import { shouldCaptureAnalytics } from "@/helpers/shouldCaptureAnalytics";
import { useIsMobileOrTabletOnClient } from "@/helpers/useIsMobileOrTabletOnClient";
import "animate.css";
import 'material-icons/iconfont/filled.css';
import { Figtree } from "next/font/google";
import Script from "next/script";
import { useEffect } from "react";
import "./globals.css";

const figtree = Figtree({ subsets: ["latin"] })

Expand Down
6 changes: 2 additions & 4 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function Home() {
Listen now
</Button>
</Link>
<a href={GITHUB_INTEGRATE_ON_YOUR_BLOG_LINK} target="_blank" referrerPolicy="same-origin" >
<a href={GITHUB_INTEGRATE_ON_YOUR_BLOG_LINK} target="_blank">
<Button
type="secondary"
className="text-lg font-bold px-6 py-2 mb-4"
Expand All @@ -48,8 +48,8 @@ export default function Home() {
</Button>
</a>
</div>
{/* ELEMENT FOR DESKTOP */}

{/* ELEMENT FOR DESKTOP */}
<div className="hidden lg:block ">
<HomePageBranding />
</div>
Expand All @@ -67,8 +67,6 @@ export default function Home() {
</div>
</div>



{/* ELEMENT FOR PAGE BOTTOM POSITIONING ON MOBILE AND TABLET*/}
<div className="block lg:hidden order-4">
<HomePageBranding />
Expand Down
3 changes: 2 additions & 1 deletion src/components/ArticleForm/PasteTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import Button from "../Button";
import TextArea from "../TextArea";

export default function PasteTab() {
const isPlayerOpen = useGenericStore((state) => state.isPlayerOpen)

const pastedArticle = useArticleStore((state) => state.pastedArticle)
const setArticleStoreStringItem = useArticleStore((state) => state.setArticleStoreStringItem)

const isPlayerOpen = useGenericStore((state) => state.isPlayerOpen)

return (
<div className="relative flex-grow animate__animated animate__fadeIn">
Expand Down
7 changes: 2 additions & 5 deletions src/components/ArticleForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DEFAULT_PASTED_ARTICLE } from "@/constants/appConstants"
import { useSplitArticleToSentences } from "@/helpers/handleArticle/useSplitArticleToSentences"
import { useDetectAndUpdateLanguage } from "@/helpers/useDetectAndUpdateLanguage"
import { useArticleStore } from "@/stores/useArticleStore"
import { useGenericStore } from "@/stores/useGenericStore"
Expand All @@ -7,26 +8,22 @@ import { useEffect, useState } from "react"
import Button from "../Button"
import FetchTab from "./FetchTab"
import PasteTab from "./PasteTab"
import { useSplitArticleToSentences } from "@/helpers/handleArticle/useSplitArticleToSentences"
import { usePlayerStore } from "@/stores/usePlayerStore"


export default function ArticleForm() {
const isPlayerOpen = useGenericStore((state) => state.isPlayerOpen)
const setShowToast = useGenericStore((state) => state.setShowToast)
const setToastType = useGenericStore((state) => state.setToastType)

const tab = useGenericStore((state) => state.tab)
const setTab = useGenericStore((state) => state.setTab)

const fetchedArticle = useArticleStore((state) => state.fetchedArticle)
const pastedArticle = useArticleStore((state) => state.pastedArticle)
const articleToSpeak = useArticleStore((state) => state.articleToSpeak)
const languageCodeOfArticleToSpeak = useArticleStore((state) => state.languageCodeOfArticleToSpeak)
const setIsPlayerOpen = useGenericStore((state) => state.setIsPlayerOpen)
const setArticleStoreStringItem = useArticleStore((state) => state.setArticleStoreStringItem)

const setPlayerState = usePlayerStore((state) => state.setPlayerState)

const [showPlayButton, setShowPlayButton] = useState(false)


Expand Down
4 changes: 2 additions & 2 deletions src/components/ImageWrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ type ImageWrapperProps = {
alt: string
}

// SSR warning to think about:
// Warning: Prop `src` did not match. Server: "/github.svg" Client: "undefined/github.svg"
// ImageWrapper component needed to selectively prefix URLs between development and production
// TODO: Fix warning: Prop `src` did not match. Server: "/github.svg" Client: "undefined/github.svg"

export default function ImageWrapper({ src, className, alt }: ImageWrapperProps) {
return (
Expand Down
1 change: 0 additions & 1 deletion src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default function Input({ className, placeholder, defaultValue, value, isD
defaultValue={defaultValue}
value={value}
disabled={isDisabled}
// title={isDisabled ? disabledTitle : ``}
onChange={onChange}
/>
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Phone/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Rectangle from "./Rectangle"
import styles from "./Phone.module.css"
import AnimatedSoundBars from "../AnimatedSoundBars"
import styles from "./Phone.module.css"
import Rectangle from "./Rectangle"

type PhoneProps = {
content: "reading" | "listening"
Expand Down
3 changes: 3 additions & 0 deletions src/components/Player/BackgroundMusicThroughVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { MutableRefObject, useEffect, useRef } from "react";

export default function BackgroundMusicThroughVideo() {
const isMobileOrTablet = useGenericStore((state) => state.isMobileOrTablet)

const playerState = usePlayerStore((state) => state.playerState)
const bgMusicVol = usePlayerStore((state) => state.bgMusicVol)

const videoRef = useRef() as MutableRefObject<HTMLVideoElement>

useEffect(() => {
Expand Down Expand Up @@ -50,6 +52,7 @@ export default function BackgroundMusicThroughVideo() {

return (
// Fixed position tiny invisible video
// TODO: process.env.NEXT_PUBLIC_LINK_PREFIX evaluates to undefined in development. Need to figure out why (already tried a lot).
<video ref={videoRef} loop className="fixed top-0 left-0 -z-50 h-2 w-1 pointer-events-none opacity-0">
<source src={`${process.env.NEXT_PUBLIC_LINK_PREFIX}/the-beat-of-nature-122841.mp4`} type="video/mp4" />
Your browser does not support video playback.
Expand Down
10 changes: 5 additions & 5 deletions src/components/Player/PlayerControls.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getIframeStatus } from "@/helpers/getIframeStatus";
import { useArticleStore } from "@/stores/useArticleStore";
import { useGenericStore } from "@/stores/useGenericStore";
import { usePlayerStore } from "@/stores/usePlayerStore";
import { MutableRefObject, useEffect, useRef } from "react";
import AnimatedSoundBars from "../AnimatedSoundBars";
import Button from "../Button";
import { MutableRefObject, useEffect, useRef } from "react";
import { usePlayerStore } from "@/stores/usePlayerStore";
import BackgroundMusicThroughVideo from "./BackgroundMusicThroughVideo";
import { useGenericStore } from "@/stores/useGenericStore";
import { getIframeStatus } from "@/helpers/getIframeStatus";

type SpeechEndReasonRef = "sentence-complete" | "pause" | "forward" | "rewind"

Expand All @@ -16,6 +16,7 @@ export default function PlayerControls() {
const setIsPlayerOpen = useGenericStore((state) => state.setIsPlayerOpen)

const sentences = useArticleStore((state) => state.sentences)

const playerState = usePlayerStore((state) => state.playerState)
const setPlayerState = usePlayerStore((state) => state.setPlayerState)
const speakingSentenceIndex = usePlayerStore((state) => state.speakingSentenceIndex)
Expand All @@ -24,7 +25,6 @@ export default function PlayerControls() {
const rate = usePlayerStore((state) => state.rate)
const pitch = usePlayerStore((state) => state.pitch)


// Get reference to the raw voice
const rawVoiceToSpeakWith: SpeechSynthesisVoice | undefined = getRawVoiceToSpeakWith()

Expand Down
10 changes: 5 additions & 5 deletions src/components/Player/PlayerHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { APP_APP_LINK, APP_HOME_LINK, GITHUB_INTEGRATE_ON_YOUR_BLOG_LINK, GITHUB_ISSUES_LINK, GITHUB_MORE_HELP_LINK } from "@/constants/appConstants";
import { getSpeakingTimeText } from "@/helpers/getSpeakingTimeText";
import { fireInstallPrompt } from "@/helpers/handlePwaLifeCycle/fireInstallPrompt";
import { useArticleStore } from "@/stores/useArticleStore";
import { useGenericStore } from "@/stores/useGenericStore";
import { usePwaStore } from "@/stores/usePwaStore";
import Button from "../Button";
import { useState } from "react";
import Button from "../Button";
import Menu from "../Menu";
import { APP_APP_LINK, APP_HOME_LINK, GITHUB_INTEGRATE_ON_YOUR_BLOG_LINK, GITHUB_ISSUES_LINK, GITHUB_MORE_HELP_LINK } from "@/constants/appConstants";


export default function PlayerHeader() {
const isPwaInstallable = usePwaStore((state) => state.isPwaInstallable)
const isMobileOrTablet = useGenericStore((state) => state.isMobileOrTablet)
const tab = useGenericStore((state) => state.tab)
const setIsPlayerOpen = useGenericStore((state) => state.setIsPlayerOpen)

const isPwaInstallable = usePwaStore((state) => state.isPwaInstallable)

const articleToSpeak = useArticleStore((state) => state.articleToSpeak)
const articleLink = useArticleStore((state) => state.articleLink)

const setIsPlayerOpen = useGenericStore((state) => state.setIsPlayerOpen)

const [isHelpOpen, setIsHelpOpen] = useState(false)


Expand Down
14 changes: 5 additions & 9 deletions src/components/Player/SpeechSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { MutableRefObject, useEffect, useRef, useState } from "react";
import Button from "../Button";
import { VoicesDropdown } from "./VoicesDropdown";
import StepInput from "./StepInput";
import { usePlayerStore } from "@/stores/usePlayerStore";
import { isLocalStorageSupported } from "@/helpers/isLocalStorageSupported";
import { useGenericStore } from "@/stores/useGenericStore";
import { usePlayerStore } from "@/stores/usePlayerStore";
import { useEffect, useState } from "react";
import Button from "../Button";
import Menu from "../Menu";
import StepInput from "./StepInput";
import { VoicesDropdown } from "./VoicesDropdown";

export default function SpeechSettings() {
const setShowToast = useGenericStore((state) => state.setShowToast)
const setToastType = useGenericStore((state) => state.setToastType)

const rate = usePlayerStore((state) => state.rate)
const pitch = usePlayerStore((state) => state.pitch)
const bgMusicVol = usePlayerStore((state) => state.bgMusicVol)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Player/StepInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Button from "../Button"
import { Item, usePlayerStore } from "@/stores/usePlayerStore"
import { SpeechSettingDefaultValues } from "@/constants/appConstants"
import { Item, usePlayerStore } from "@/stores/usePlayerStore"
import Button from "../Button"

type StepInputProps = {
label: string,
Expand Down
8 changes: 4 additions & 4 deletions src/components/Player/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useIsFrequentListener } from "@/helpers/useIsFrequentListener"
import { useGenericStore } from "@/stores/useGenericStore"
import { usePlayerStore } from "@/stores/usePlayerStore"
import { useEffect } from "react"
import PlayerControls from "./PlayerControls"
import PlayerHeader from "./PlayerHeader"
import SpeechSettings from "./SpeechSettings"
import { useEffect } from "react"
import { useGenericStore } from "@/stores/useGenericStore"
import { usePlayerStore } from "@/stores/usePlayerStore"
import { useIsFrequentListener } from "@/helpers/useIsFrequentListener"

// https://dev.to/jankapunkt/cross-browser-speech-synthesis-the-hard-way-and-the-easy-way-353

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/handleArticle/useSplitArticleToSentences.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { maxSentenceLength } from "@/constants/appConstants";
import { useArticleStore } from "@/stores/useArticleStore";
import { useEffect } from "react";
import { useGenericStore } from "@/stores/useGenericStore";
import { useEffect } from "react";

export function useSplitArticleToSentences() {
const isMobileOrTablet = useGenericStore((state) => state.isMobileOrTablet)
Expand Down
1 change: 1 addition & 0 deletions src/helpers/setUpWebSpeech/useChooseBestVoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isLocalStorageSupported } from "../isLocalStorageSupported";

export function useChooseBestVoice() {
const languageCodeOfArticleToSpeak = useArticleStore((state) => state.languageCodeOfArticleToSpeak)

const voices = usePlayerStore((state) => state.voices)
const setVoiceToSpeakWith = usePlayerStore((state) => state.setVoiceToSpeakWith)

Expand Down
7 changes: 4 additions & 3 deletions src/helpers/useIsFrequentListener.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { FREQUENT_LISTENER_THRESHOLD } from "@/constants/appConstants";
import { useGenericStore } from "@/stores/useGenericStore";
import { useEffect } from "react";
import { isLocalStorageSupported } from "./isLocalStorageSupported";
import { useGenericStore } from "@/stores/useGenericStore";
import { FREQUENT_LISTENER_THRESHOLD } from "@/constants/appConstants";

// custom hook that increments count on every mount
// Determine current frequent listener status and updates store variable
export function useIsFrequentListener() {
const setIsFrequentListener = useGenericStore((state) => state.setIsFrequentListener)

useEffect(() => {
if (isLocalStorageSupported()) {
const data = window.localStorage.getItem("listenCount")
Expand All @@ -18,7 +19,7 @@ export function useIsFrequentListener() {
setIsFrequentListener(true)
}
else
window.localStorage.setItem("listenCount", `1`)
window.localStorage.setItem("listenCount", "1")
}
}, [])
}
1 change: 0 additions & 1 deletion src/stores/useArticleStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ export const useArticleStore = create<ArticleStoreState>(
sentences: [],
setSentences: (newValue: string[]) => set({ sentences: newValue }),
setArticleStoreStringItem: (item, newValue) => set({ [item]: newValue }),

}))
3 changes: 2 additions & 1 deletion src/stores/usePlayerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ export const usePlayerStore = create<PlayerStoreState>(
setPlayerState: (newValue: PlayerState) => set({ playerState: newValue }),
speakingSentenceIndex: 0,
setSpeakingSentenceIndex: (newValue: number) => set({ speakingSentenceIndex: newValue })
}))
})
)
3 changes: 2 additions & 1 deletion src/stores/usePwaStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const usePwaStore = create<PwaStoreState>(
(set) => ({
isPwaInstallable: false,
setIsPwaInstallable: (newValue) => set({ isPwaInstallable: newValue })
}))
})
)

0 comments on commit 859f493

Please sign in to comment.