pull/30/merge
Kamal 3 years ago committed by GitHub
commit 6c0fac216e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,10 +2,15 @@ import React from 'react';
import config from '../../config.json';
export const Ps1 = () => {
let [visitorName, setVisitorName] = React.useState('');
React.useEffect(() => {
let name = window.sessionStorage.getItem('visitorName');
setVisitorName(name);
}, [visitorName]);
return (
<div>
<span className="text-light-yellow dark:text-dark-yellow">
{config.ps1_username}
{visitorName}
</span>
<span className="text-light-gray dark:text-dark-gray">@</span>
<span className="text-light-green dark:text-dark-green">

@ -1,7 +1,8 @@
import React from 'react';
import '../styles/global.css';
import Head from 'next/head';
import config from '../../config.json';
import { useLayoutEffect, useState } from 'react';
const App = ({ Component, pageProps }) => {
const inputRef = React.useRef<HTMLInputElement>(null);
@ -9,6 +10,36 @@ const App = ({ Component, pageProps }) => {
inputRef.current.focus();
};
useLayoutEffect(() => {
let html = document.querySelector('html');
html.classList.add('dark');
let theme = window.sessionStorage.getItem('theme');
if (theme == 'dark') {
html.classList.add('dark');
} else if (theme == 'light') {
html.classList.remove('dark');
}
}, []);
React.useEffect(() => {
const askName = 'What is your name?';
let visitor: string;
if (!window.sessionStorage) {
window.prompt(askName);
}
visitor = window.sessionStorage.getItem('visitorName');
if (!visitor) {
visitor = window.prompt(askName);
if (['', undefined, null].includes(visitor)) {
visitor = config.ps1_username;
}
window.sessionStorage.setItem('visitorName', visitor);
}
}, []);
return (
<>
<Head>

@ -52,6 +52,22 @@ here are the ways you can support my work:
`;
};
// theme
export const theme = async (args: string[]): Promise<string> => {
let html = document.querySelector('html');
if (`${args}` == 'dark') {
window.sessionStorage.setItem('theme', 'dark');
html.classList.add('dark');
return `changing theme to dark ...`;
} else if (`${args}` == 'light') {
window.sessionStorage.setItem('theme', 'light');
html.classList.remove('dark');
return `changing theme to light ..`;
} else {
return `available options are dark and light.`;
}
};
// Contact
export const email = async (args: string[]): Promise<string> => {
window.open(`mailto:${config.email}`);
@ -97,7 +113,8 @@ export const echo = async (args: string[]): Promise<string> => {
};
export const whoami = async (args: string[]): Promise<string> => {
return `${config.ps1_username}`;
let visitor = window.sessionStorage.getItem('visitorName');
return `${visitor}`;
};
export const ls = async (args: string[]): Promise<string> => {

@ -5,7 +5,7 @@ module.exports = {
'./src/pages/**/*.{js,ts,jsx,tsx}',
'./src/components/**/*.{js,ts,jsx,tsx}',
],
darkMode: 'media', // or 'media' or 'class'
darkMode: 'class', // or 'media' or 'class'
theme: {
colors: {
transparent: 'transparent',

Loading…
Cancel
Save