Skip to content

Commit 08e8b0a

Browse files
committed
Refactor package.json and pnpm-lock.yaml to add lz-string dependency
1 parent d22ac90 commit 08e8b0a

File tree

6 files changed

+71
-100
lines changed

6 files changed

+71
-100
lines changed

app/[code]/page.tsx

Lines changed: 51 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5,143 +5,104 @@ import Link from 'next/link';
55
import { useSearchParams } from 'next/navigation';
66
import { io } from 'socket.io-client';
77
import debounce from 'lodash.debounce';
8+
import LZString from 'lz-string';
89

910
const socket = io('https://codenow-server.onrender.com');
10-
// const socket = io(process.env.SOCKET_URL);
1111

1212
const ShareCodePage: React.FC = () => {
1313
const searchParams = useSearchParams();
14-
const initialCode = searchParams.get('code') || '';
15-
const [sharedCode, setSharedCode] = useState<string>(initialCode);
14+
const initialCode = LZString.decompressFromEncodedURIComponent(searchParams.get('code') || '') || '';
15+
const [sharedCode, setSharedCode] = useState(initialCode);
1616
const [toastMessage, setToastMessage] = useState<string | null>(null);
1717
const textareaRef = useRef<HTMLTextAreaElement>(null);
1818

1919
useEffect(() => {
20-
if (initialCode) {
21-
setSharedCode(initialCode);
22-
}
20+
if (initialCode) setSharedCode(initialCode);
2321

24-
socket.on('codeUpdate', (newCode: string) => {
25-
console.log('Received code update:', newCode);
26-
setSharedCode(newCode);
27-
});
22+
const handleCodeUpdate = (newCode: string) => setSharedCode(newCode);
23+
const handleMessage = (message: string) => console.log(message);
2824

29-
socket.on('message', (message: string) => {
30-
console.log(message);
31-
});
25+
socket.on('codeUpdate', handleCodeUpdate);
26+
socket.on('message', handleMessage);
3227

3328
return () => {
34-
socket.off('codeUpdate');
35-
socket.off('message');
29+
socket.off('codeUpdate', handleCodeUpdate);
30+
socket.off('message', handleMessage);
3631
};
3732
}, [initialCode]);
3833

34+
const showToast = (message: string) => {
35+
setToastMessage(message);
36+
setTimeout(() => setToastMessage(null), 3000);
37+
};
38+
3939
const handleCopy = () => {
4040
navigator.clipboard.writeText(sharedCode);
41-
setToastMessage("The code has been copied to your clipboard.");
42-
setTimeout(() => setToastMessage(null), 3000);
41+
showToast("The code has been copied to your clipboard.");
4342
};
4443

4544
const handleShare = () => {
46-
const url = `${window.location.origin}${window.location.pathname}?code=${encodeURIComponent(sharedCode)}`;
47-
navigator.clipboard.writeText(url);
48-
setToastMessage("The shareable link has been copied to your clipboard.");
49-
setTimeout(() => setToastMessage(null), 3000);
45+
const compressedCode = LZString.compressToEncodedURIComponent(sharedCode);
46+
navigator.clipboard.writeText(`${window.location.origin}${window.location.pathname}?code=${compressedCode}`);
47+
showToast("The shareable link has been copied to your clipboard.");
5048
};
5149

52-
// Debounced function to emit codeChange with URL
53-
const debouncedEmitCodeChange = useRef(
54-
debounce((newCode) => {
55-
const url = window.location.href; // Capture the current URL
56-
console.log('Emitting Code Change:', { newCode, url }); // Debugging line
57-
socket.emit('codeChange', { newCode, url }); // Emit both the new code and the URL
58-
localStorage.setItem('sharedCode', newCode);
59-
}, 500)
60-
).current;
50+
const debouncedEmitCodeChange = useRef(debounce((newCode: string) => {
51+
socket.emit('codeChange', { newCode, url: window.location.href });
52+
localStorage.setItem('sharedCode', newCode);
53+
}, 500)).current;
6154

6255
const handleTextareaChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
6356
const newCode = e.target.value;
64-
console.log('New Code:', newCode); // Debugging line
6557
setSharedCode(newCode);
6658
debouncedEmitCodeChange(newCode);
6759
};
6860

69-
const calculateLineNumbers = () => {
70-
if (textareaRef.current) {
71-
const lineCount = textareaRef.current.value.split('\n').length;
72-
return Array.from({ length: lineCount }, (_, i) => i + 1);
73-
}
74-
return [];
75-
};
76-
77-
const lines = calculateLineNumbers();
61+
const lines = textareaRef.current ? Array.from({ length: textareaRef.current.value.split('\n').length }, (_, i) => i + 1) : [];
7862

7963
return (
8064
<div className="flex flex-col min-h-screen font-sans bg-gray-950 text-gray-100">
81-
<header className="px-4 lg:px-6 h-14 flex items-center justify-between">
82-
<Link className="flex items-center justify-center" href="/">
83-
<Code className="h-6 w-6 mr-2" />
84-
<span className="font-bold text-xl">CodeNow</span>
85-
</Link>
86-
<a
87-
href="https://github.com/krishvsoni/CodeNow"
88-
target="_blank"
89-
rel="noopener noreferrer"
90-
className="flex items-center text-sm text-blue-500 hover:underline"
91-
>
92-
<svg
93-
className="h-5 w-5 mr-1"
94-
fill="currentColor"
95-
viewBox="0 0 24 24"
96-
xmlns="http://www.w3.org/2000/svg"
97-
>
98-
<path
99-
fillRule="evenodd"
100-
d="M12 0C5.37 0 0 5.37 0 12c0 5.3 3.438 9.8 8.205 11.385.6.11.82-.26.82-.577v-2.165c-3.338.726-4.042-1.61-4.042-1.61-.546-1.387-1.333-1.757-1.333-1.757-1.09-.745.083-.73.083-.73 1.205.084 1.84 1.237 1.84 1.237 1.07 1.835 2.807 1.305 3.492.997.108-.775.42-1.305.763-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.467-2.38 1.235-3.22-.123-.303-.535-1.523.117-3.176 0 0 1.008-.322 3.3 1.23.957-.266 1.98-.398 3-.403 1.02.005 2.043.137 3 .403 2.29-1.552 3.297-1.23 3.297-1.23.653 1.653.24 2.873.118 3.176.77.84 1.233 1.91 1.233 3.22 0 4.61-2.803 5.625-5.475 5.92.43.37.823 1.102.823 2.222v3.293c0 .32.218.694.825.576C20.565 21.795 24 17.295 24 12c0-6.63-5.37-12-12-12z"
101-
clipRule="evenodd"
102-
/>
103-
</svg>
104-
CodeNow
105-
</a>
106-
</header>
107-
65+
<header className="px-4 lg:px-6 h-14 flex items-center justify-between">
66+
<Link className="flex items-center justify-center" href="/">
67+
<Code className="h-6 w-6 mr-2" />
68+
<span className="font-bold text-xl">CodeNow</span>
69+
</Link>
70+
<a
71+
href="https://github.com/krishvsoni/CodeNow"
72+
target="_blank"
73+
rel="noopener noreferrer"
74+
className="flex items-center text-sm text-blue-500 hover:underline"
75+
>
76+
<svg className="h-5 w-5 mr-1" fill="currentColor" viewBox="0 0 24 24">
77+
<path fillRule="evenodd" d="M12 0C5.37 0 0 5.37 0 12c0 5.3 3.438 9.8 8.205 11.385.6.11.82-.26.82-.577v-2.165c-3.338.726-4.042-1.61-4.042-1.61-.546-1.387-1.333-1.757-1.333-1.757-1.09-.745.083-.73.083-.73 1.205.084 1.84 1.237 1.84 1.237 1.07 1.835 2.807 1.305 3.492.997.108-.775.42-1.305.763-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.467-2.38 1.235-3.22-.123-.303-.535-1.523.117-3.176 0 0 1.008-.322 3.3 1.23.957-.266 1.98-.398 3-.403 1.02.005 2.043.137 3 .403 2.29-1.552 3.297-1.23 3.297-1.23.653 1.653.24 2.873.118 3.176.77.84 1.233 1.91 1.233 3.22 0 4.61-2.803 5.625-5.475 5.92.43.37.823 1.102.823 2.222v3.293c0 .32.218.694.825.576C20.565 21.795 24 17.295 24 12c0-6.63-5.37-12-12-12z" clipRule="evenodd" />
78+
</svg>
79+
CodeNow
80+
</a>
81+
</header>
10882

10983
<main className="flex-1 p-4 md:p-6">
110-
<div className="max-w-4xl mx-auto space-y-4">
111-
<div className="flex items-center justify-between">
112-
<h1 className="text-2xl font-bold">Shared Code</h1>
113-
</div>
84+
<div className="w-full max-w-4xl lg:max-w-full mx-auto space-y-4">
85+
<h1 className="text-2xl font-bold">Shared Code</h1>
11486
<div className="border border-gray-800 rounded-lg overflow-hidden">
11587
<div className="bg-gray-900 p-2 flex justify-between items-center">
116-
<span className="text-sm font-medium"></span>
11788
<div className="flex space-x-2">
118-
<button
119-
className="p-2 bg-gray-800 hover:bg-gray-700 rounded text-gray-300"
120-
onClick={handleCopy}
121-
>
122-
<Copy className="h-4 w-4 inline" />
123-
<span className="sr-only">Copy code</span>
89+
<button className="p-2 bg-gray-800 hover:bg-gray-700 rounded text-gray-300" onClick={handleCopy}>
90+
<Copy className="h-4 w-4 inline" /> <span className="sr-only">Copy code</span>
12491
</button>
125-
<button
126-
className="p-2 bg-gray-800 hover:bg-gray-700 rounded text-gray-300"
127-
onClick={handleShare}
128-
>
129-
<Share2 className="h-4 w-4 inline" />
130-
<span className="sr-only">Share code</span>
92+
<button className="p-2 bg-gray-800 hover:bg-gray-700 rounded text-gray-300" onClick={handleShare}>
93+
<Share2 className="h-4 w-4 inline" /> <span className="sr-only">Share code</span>
13194
</button>
13295
</div>
13396
</div>
13497
<div className="relative">
135-
<div className="absolute top-0 left-0 h-full w-10 bg-gray-900 border-r border-gray-800 flex flex-col items-center pt-4 text-gray-500 text-sm select-none">
98+
<div className="absolute top-0 left-0 h-[600px] bg-gray-900 border-r border-gray-800 flex flex-col items-center pt-4 text-gray-500 text-sm select-none">
13699
{lines.map((lineNumber) => (
137-
<div key={lineNumber} className="h-6 w-full text-right pr-2">
138-
{lineNumber}
139-
</div>
100+
<div key={lineNumber} className="h-6 w-full text-right pr-2">{lineNumber}</div>
140101
))}
141102
</div>
142103
<textarea
143104
ref={textareaRef}
144-
className="w-full h-[400px] bg-gray-950 text-gray-100 p-4 pl-12 font-mono text-sm resize-none focus:outline-none"
105+
className="w-full h-[600px] bg-gray-950 text-gray-100 p-4 pl-12 font-mono text-sm resize-none focus:outline-none"
145106
value={sharedCode}
146107
onChange={handleTextareaChange}
147108
spellCheck="false"
@@ -160,9 +121,7 @@ const ShareCodePage: React.FC = () => {
160121

161122
<footer className="flex flex-col gap-2 sm:flex-row py-6 w-full shrink-0 items-center justify-center px-4 md:px-6 border-t border-gray-800">
162123
<p className="text-sm text-gray-400">© 2024 CodeNow. All rights reserved.</p>
163-
<p className="text-slate-600 font-mono hover:text-white transition-colors duration-300">
164-
built by Krish Soni 🚀
165-
</p>
124+
<p className="text-slate-600 font-mono hover:text-white transition-colors duration-300">built by Krish Soni</p>
166125
</footer>
167126
</div>
168127
);

app/favicon.ico

-10.3 KB
Binary file not shown.

app/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ const geistMono = localFont({
1515

1616
export const metadata: Metadata = {
1717
title: "CodeNow",
18-
description: "Generated by create next app",
18+
description: "CodeNow is the realtime code sharing platform that brings developers together. Collaborate, learn, and create in perfect sync.",
1919
};
2020

21+
22+
2123
export default function RootLayout({
2224
children,
2325
}: Readonly<{

app/page.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function Component() {
3535
href="https://github.com/krishvsoni/CodeNow"
3636
target="_blank"
3737
rel="noopener noreferrer"
38-
className="flex items-center text-sm text-blue-500 hover:underline"
38+
className="flex items-center text-sm text-blue-500 "
3939
>
4040
<svg
4141
className="h-5 w-5 mr-1"
@@ -91,7 +91,7 @@ export default function Component() {
9191
{/* Modal for entering code */}
9292
{isModalOpen && (
9393
<motion.div
94-
className="fixed inset-0 bg-gray-900 bg-opacity-75 flex justify-center items-center"
94+
className="fixed inset-0 bg-gray-900 bg-opacity-75 flex justify-center items-center z-50"
9595
initial={{ opacity: 0 }}
9696
animate={{ opacity: 1 }}
9797
exit={{ opacity: 0 }}
@@ -108,7 +108,7 @@ export default function Component() {
108108
<input
109109
type="text"
110110
className="w-full px-3 py-2 bg-gray-700 text-white rounded mb-4"
111-
placeholder="Enter code here..."
111+
placeholder="your room code "
112112
value={code}
113113
onChange={(e) => setCode(e.target.value)}
114114
/>
@@ -167,8 +167,8 @@ export default function Component() {
167167
transition={{ duration: 0.5, delay: 0.2 }}
168168
>
169169
<Users className="h-10 w-10 text-purple-500" />
170-
<h2 className="text-xl font-bold">Team Management</h2>
171-
<p className="text-gray-400">Easily manage your team, projects, and permissions all in one place.</p>
170+
<h2 className="text-xl font-bold">Team Work</h2>
171+
<p className="text-gray-400">Easily manage your team, projects, and code all in one place.</p>
172172
</motion.div>
173173
</div>
174174
</div>
@@ -202,10 +202,10 @@ export default function Component() {
202202
</motion.section>
203203
</main>
204204

205-
<footer className="flex flex-col gap-2 sm:flex-row py-6 w-full shrink-0 items-center justify-center px-4 md:px-6 border-t border-gray-800">
205+
<footer className="flex flex-col gap-2 sm:flex-row py-6 w-full shrink-0 items-center justify-center px-4 md:px-6 border-t border-gray-800">
206206
<p className="text-sm text-gray-400">© 2024 CodeNow. All rights reserved.</p>
207207
<p className="text-slate-600 font-mono hover:text-white transition-colors duration-300">
208-
built by Krish Soni 🚀
208+
built by Krish Soni
209209
</p>
210210
</footer>
211211
</div>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"highlight.js": "^11.10.0",
1818
"lodash.debounce": "^4.0.8",
1919
"lucide-react": "^0.447.0",
20+
"lz-string": "^1.5.0",
2021
"next": "14.2.14",
2122
"prismjs": "^1.29.0",
2223
"react": "^18",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)