Skip to content

Commit c45e525

Browse files
committed
update
1 parent d06c0f9 commit c45e525

File tree

9 files changed

+72
-43
lines changed

9 files changed

+72
-43
lines changed

app/globals.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ body {
4242
// display: flex;
4343
// flex-direction: column;
4444

45+
// remove blue tap highlight on mobile
46+
-webkit-tap-highlight-color: transparent;
47+
4548
main{
4649
// flex: 1;
4750
min-height: 100vh;

app/layout.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { headers } from 'next/headers'
33
import AuthContext from '@/context/AuthContext';
44
import Footer from '@/components/shared/Footer'
55
import './globals.scss'
6-
import { ThemeProvider } from '@/context/ThemeContext';
6+
import { ThemeProvider, ThemeContext } from '@/context/ThemeContext';
7+
78

89
async function getSession(cookies) {
910
const response = await fetch(`${process.env.NEXTAUTH_URL}/api/auth/session`, {

app/variables.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ $variables-light: (
4444
}
4545
}
4646

47-
html[data-theme="light"] {
47+
html[data-theme="light"] ,
48+
body[data-theme="light"]
49+
{
4850

4951
@each $key,
5052
$value in $variables-light {

components/pages/all/CardSkeleton/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
2-
import 'react-loading-skeleton/dist/skeleton.css'
31
import styles from '../Card/card.module.scss'
2+
import 'react-loading-skeleton/dist/skeleton.css'
3+
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
4+
import { ThemeContext } from "@/context/ThemeContext";
5+
import { useContext } from "react";
46

57
const CardSkeleton = () => {
8+
9+
const { theme } = useContext(ThemeContext);
10+
const baseColor = theme === "dark" ? "#343434" : "#f5f5f5";
11+
const highlightColor = theme === "dark" ? "#565656" : "#e5e5e5";
12+
613
return (
714
<div className={styles.card + " " + styles.skeleton}>
815
<div className={styles.card__body}>
9-
<SkeletonTheme baseColor="#343434" highlightColor="#565656">
16+
<SkeletonTheme baseColor={baseColor} highlightColor={highlightColor}>
1017
<Skeleton height={200} />
1118
<Skeleton height={22} width={'50%'} style={{ margin: '10px 0 5px 0' }} />
1219
<Skeleton height={14} count={8} />

components/pages/all/SnippetSkeleton/index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
1+
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
22
import 'react-loading-skeleton/dist/skeleton.css'
3+
import { ThemeContext } from "@/context/ThemeContext";
4+
import { useContext } from "react";
35

46
const ResultSkeleton = () => {
5-
return (
6-
<SkeletonTheme
7-
count={9}
8-
baseColor="#444"
9-
highlightColor="#888"
10-
>
11-
<br/>
127

13-
<p style={{width: '40%' }}>{<Skeleton height={14} />}</p>
14-
<h1>{<Skeleton />}</h1>
15-
<p>{<Skeleton />}</p>
16-
<p>{<Skeleton />}</p>
8+
const { theme } = useContext(ThemeContext);
9+
const baseColor = theme === "dark" ? "#343434" : "#f5f5f5";
10+
const highlightColor = theme === "dark" ? "#565656" : "#e5e5e5";
11+
12+
return (
13+
<SkeletonTheme count={9} baseColor={baseColor} highlightColor={highlightColor}>
14+
<br />
15+
<p style={{ width: '40%' }}>{<Skeleton height={14} />}</p>
16+
<h1>{<Skeleton />}</h1>
17+
<p>{<Skeleton />}</p>
18+
<p>{<Skeleton />}</p>
1719
</SkeletonTheme>
1820
)
1921
}

components/pages/images/CardSkeleton/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
22
import 'react-loading-skeleton/dist/skeleton.css'
3+
import { ThemeContext } from "@/context/ThemeContext";
4+
import { useContext } from "react";
35

46
const CardSkeleton = () => {
7+
8+
const { theme } = useContext(ThemeContext);
9+
const baseColor = theme === "dark" ? "#343434" : "#f5f5f5";
10+
const highlightColor = theme === "dark" ? "#565656" : "#e5e5e5";
11+
512
return (
613
<div>
7-
<SkeletonTheme baseColor="#343434" highlightColor="#565656">
14+
<SkeletonTheme baseColor={baseColor} highlightColor={highlightColor}>
815
<Skeleton height={160} />
916
<Skeleton height={16} width={'65%'} style={{ margin: '6px 0 4px 0' }} />
1017
<Skeleton height={12} count={2} />

components/pages/videos/CardSkeleton/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
22
import 'react-loading-skeleton/dist/skeleton.css'
33
import styles from "../VideoCard/videoCard.module.scss"
4+
import { ThemeContext } from "@/context/ThemeContext";
5+
import { useContext } from "react";
46

57
const CardSkeleton = () => {
8+
9+
const { theme } = useContext(ThemeContext);
10+
const baseColor = theme === "dark" ? "#343434" : "#f5f5f5";
11+
const highlightColor = theme === "dark" ? "#565656" : "#e5e5e5";
12+
613
return (
714
<div>
8-
<SkeletonTheme baseColor="#343434" highlightColor="#565656">
15+
<SkeletonTheme baseColor={baseColor} highlightColor={highlightColor}>
916
<div className={styles.videoCard + ' ' + styles.skeleton}>
1017
<Skeleton className={styles.thumbnail} height={160} />
1118
<div className={styles.content}>

components/shared/SearchBar/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const fetchSuggestions = async (search, signal) => {
2323
}
2424

2525
const renderSuggestion = suggestion => (
26-
<p onClick={() => console.log("clicked")}>
26+
<p>
2727
<span className={styles.searchIcon}><FaSearch /></span> {suggestion}
2828
</p>
2929
);
@@ -47,13 +47,7 @@ const SearchBar = (props) => {
4747
const query = searchParams.get("q");
4848

4949
const [search, setSearch] = useState(props.value || "");
50-
const [suggestions, setSuggestions] = useState([
51-
"World Cup",
52-
"Elon Musk",
53-
"Facebook",
54-
"Artificial Intelligence",
55-
"Narendra Modi",
56-
]);
50+
const [suggestions, setSuggestions] = useState([]);
5751

5852

5953
useEffect(() => {
@@ -87,7 +81,15 @@ const SearchBar = (props) => {
8781

8882
const onSuggestionSelected = (e, { suggestion }) => {
8983
console.log("selected", suggestion);
84+
9085
setSearch(suggestion);
86+
87+
if (pathname === "/") {
88+
router.push(`/search?q=${suggestion}`);
89+
} else {
90+
router.push(`${pathname}?q=${suggestion}`);
91+
}
92+
9193
}
9294

9395
return (
@@ -99,7 +101,7 @@ const SearchBar = (props) => {
99101
renderSuggestion={renderSuggestion}
100102
getSuggestionValue={suggestion => suggestion}
101103
onSuggestionSelected={onSuggestionSelected}
102-
renderInputComponent={renderInputComponent}
104+
renderInputComponent={renderInputComponent}
103105
inputProps={{
104106
placeholder: 'Start typing to search ...',
105107
value: search || "",

context/ThemeContext.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,26 @@ import React, { createContext, useState, useEffect } from 'react';
55
export const ThemeContext = createContext();
66

77
export const ThemeProvider = ({ children }) => {
8-
const [theme, setTheme] = useState('dark');
9-
10-
const toggleTheme = () => {
11-
setTheme(theme === 'light' ? 'dark' : 'light');
12-
};
8+
const [theme, setTheme] = useState();
139

1410
useEffect(() => {
1511
const localTheme = localStorage.getItem('theme');
16-
console.log('localTheme', localTheme);
12+
console.log('Get LocalStorage theme', localTheme);
1713

18-
if (localTheme) {
19-
setTheme(localTheme);
20-
} else {
21-
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
22-
setTheme(prefersDarkMode ? 'dark' : 'light');
23-
}
14+
setTheme(localTheme || 'dark');
2415
}, []);
2516

17+
const toggleTheme = () => {
18+
setTheme(theme === 'light' ? 'dark' : 'light');
19+
};
20+
2621
useEffect(() => {
27-
localStorage.setItem('theme', theme);
28-
document.documentElement.setAttribute('data-theme', theme); // set data-theme attribute on the root HTML tag
29-
console.log('theme', theme);
22+
// if theme available and not equal to undefined or null
23+
if (theme && theme !== 'undefined' && theme !== 'null') {
24+
localStorage.setItem('theme', theme);
25+
console.log('Set LocalStorage theme', theme);
26+
document.documentElement.setAttribute('data-theme', theme);
27+
}
3028
}, [theme]);
3129

3230
return (

0 commit comments

Comments
 (0)