-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.md~
1076 lines (935 loc) · 29.1 KB
/
README.md~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<div align="center">
<br />
<a href="https://youtu.be/lie0cr3wESQ" target="_blank">
<img src="https://i.ibb.co/wR9G2k3/Readme-Thumbnail.png" alt="Project Banner">
</a>
<br />
<div>
<img src="https://img.shields.io/badge/-Next_JS-black?style=for-the-badge&logoColor=white&logo=nextdotjs&color=000000" alt="nextdotjs" />
<img src="https://img.shields.io/badge/-TypeScript-black?style=for-the-badge&logoColor=white&logo=typescript&color=3178C6" alt="typescript" />
<img src="https://img.shields.io/badge/-Tailwind_CSS-black?style=for-the-badge&logoColor=white&logo=tailwindcss&color=06B6D4" alt="tailwindcss" />
<img src="https://img.shields.io/badge/-Appwrite-black?style=for-the-badge&logoColor=white&logo=appwrite&color=FD366E" alt="appwrite" />
</div>
<h3 align="center">Storage and File Sharing Platform</h3>
<div align="center">
In this repository, I am following along with Adrian Hajdin from JavaScript Mastery (YouTube) to build a Storage and File Sharing Platform.
https://www.youtube.com/watch?v=lie0cr3wESQ&t=2051s&ab_channel=JavaScriptMastery
https://github.com/adrianhajdin
</div>
</div>
## 📋 <a name="table">Table of Contents</a>
1. 🤖 [Introduction](#introduction)
2. ⚙️ [Tech Stack](#tech-stack)
3. 🔋 [Features](#features)
4. 🤸 [Quick Start](#quick-start)
5. 🕸️ [Snippets (Code to Copy)](#snippets)
6. 🔗 [Assets](#links)
7. 🚀 [More](#more)
## 🚨 Tutorial
This repository contains the code corresponding to an in-depth tutorial available on JavaScript Mastery's YouTube
channel, <a href="https://www.youtube.com/@javascriptmastery/videos" target="_blank"><b>JavaScript Mastery</b></a>.
<a href="https://youtu.be/lie0cr3wESQ?si=yLQyhMrYLjpysnqE" target="_blank"><img src="https://github.com/sujatagunale/EasyRead/assets/151519281/1736fca5-a031-4854-8c09-bc110e3bc16d" /></a>
## <a name="introduction">🤖 Introduction</a>
A storage management and file sharing platform that lets users effortlessly upload, organize, and share files. Built with the latest Next.js 15 and the Appwrite Node SDK, utilizing advanced features for seamless file management.
If you're getting started and need assistance or face any bugs, join our active Discord community with over **34k+**
members. It's a place where people help each other out.
<a href="https://discord.com/invite/n6EdbFJ" target="_blank"><img src="https://github.com/sujatagunale/EasyRead/assets/151519281/618f4872-1e10-42da-8213-1d69e486d02e" /></a>
## <a name="tech-stack">⚙️ Tech Stack</a>
- React 19
- Next.js 15
- Appwrite
- TailwindCSS
- ShadCN
- TypeScript
## <a name="features">🔋 Features</a>
👉 **User Authentication with Appwrite**: Implement signup, login, and logout functionality using Appwrite's authentication system.
👉 **FIle Uploads**: Effortlessly upload a variety of file types, including documents, images, videos, and audio, ensuring all your important data.
👉 **View and Manage Files**: Users can browse through their uploaded files stored in Appwrite storage, view on a new tab, rename file or delete.
👉 **Download Files**: Users can download their uploaded files giving them instant access to essential documents.
👉 **File Sharing**: Users can easily share their uploaded files with others, enabling collaboration and easy access to important content.
👉 **Dashboard**: Gain insights at a glance with a dynamic dashboard that showcases total and consumed storage, recent uploads, and a summary of files grouped by type.
👉 **Global Search**: Users can quickly find files and shared content across the platform with a robust global search feature.
👉 **Sorting Options**: Organize files efficiently by sorting them by date, name, or size, making file management a breeze.
👉 **Modern Responsive Design**: A fresh and minimalist UI that emphasizes usability, ensuring a clean aesthetic across all devices.
and many more, including the latest **React 19**, **Next.js 15** and **Appwrite** features alongside code architecture and
reusability
## <a name="quick-start">🤸 Quick Start</a>
Follow these steps to set up the project locally on your machine.
**Prerequisites**
Make sure you have the following installed on your machine:
- [Git](https://git-scm.com/)
- [Node.js](https://nodejs.org/en)
- [npm](https://www.npmjs.com/) (Node Package Manager)
**Cloning the Repository**
```bash
git clone https://github.com/fum9ya/jsm_storeit.git
```
**Installation**
Install the project dependencies using npm:
```bash
npm install
```
**Set Up Environment Variables**
Create a new file named `.env.local` in the root of your project and add the following content:
```env
NEXT_PUBLIC_APPWRITE_ENDPOINT="https://cloud.appwrite.io/v1"
NEXT_PUBLIC_APPWRITE_PROJECT=""
NEXT_PUBLIC_APPWRITE_DATABASE=""
NEXT_PUBLIC_APPWRITE_USERS_COLLECTION=""
NEXT_PUBLIC_APPWRITE_FILES_COLLECTION=""
NEXT_PUBLIC_APPWRITE_BUCKET=""
NEXT_APPWRITE_KEY=""
```
Replace the values with your actual Appwrite credentials. You can obtain these credentials by signing up &
creating a new project on the [Appwrite website](https://appwrite.io/).
**Running the Project**
```bash
npm run dev
```
Open [http://localhost:3000](http://localhost:3000) in your browser to view the project.
## <a name="snippets">🕸️ Snippets</a>
<details>
<summary><code>tailwind.config.ts</code></summary>
```typescript
import type { Config } from 'tailwindcss';
const config: Config = {
darkMode: ['class'],
content: [
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {
colors: {
brand: {
DEFAULT: '#FA7275',
100: '#EA6365',
},
red: '#FF7474',
error: '#b80000',
green: '#3DD9B3',
blue: '#56B8FF',
pink: '#EEA8FD',
orange: '#F9AB72',
light: {
100: '#333F4E',
200: '#A3B2C7',
300: '#F2F5F9',
400: '#F2F4F8',
},
dark: {
100: '#04050C',
200: '#131524',
},
},
fontFamily: {
poppins: ['var(--font-poppins)'],
},
boxShadow: {
'drop-1': '0px 10px 30px 0px rgba(66, 71, 97, 0.1)',
'drop-2': '0 8px 30px 0 rgba(65, 89, 214, 0.3)',
'drop-3': '0 8px 30px 0 rgba(65, 89, 214, 0.1)',
},
borderRadius: {
lg: 'var(--radius)',
md: 'calc(var(--radius) - 2px)',
sm: 'calc(var(--radius) - 4px)',
},
keyframes: {
'caret-blink': {
'0%,70%,100%': { opacity: '1' },
'20%,50%': { opacity: '0' },
},
},
animation: {
'caret-blink': 'caret-blink 1.25s ease-out infinite',
},
},
},
plugins: [require('tailwindcss-animate')],
};
export default config;
```
</details>
<details>
<summary><code>globals.css</code></summary>
```css
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
* {
@apply scroll-smooth;
}
body {
@apply bg-white text-dark-200 min-h-screen;
}
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
height: 3px;
border-radius: 50px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: #e5e7eb;
border-radius: 50px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: #fa7275;
}
/* Remove scrollbar */
.remove-scrollbar::-webkit-scrollbar {
width: 0px;
height: 0px;
border-radius: 0px;
}
.remove-scrollbar::-webkit-scrollbar-track {
background: transparent;
}
.remove-scrollbar::-webkit-scrollbar-thumb {
background: transparent;
border-radius: 0px;
}
.remove-scrollbar::-webkit-scrollbar-thumb:hover {
/* background: #1e2238; */
background: transparent;
}
.recharts-responsive-container {
height: initial !important;
}
}
@layer utilities {
/* ===== TYPOGRAPHY */
.h1 {
@apply text-[34px] leading-[42px] font-bold;
}
.h2 {
@apply text-[24px] leading-[36px] font-bold;
}
.h3 {
@apply text-[20px] leading-[28px] font-semibold;
}
.h4 {
@apply text-[18px] leading-[20px] font-medium;
}
.h5 {
@apply text-[16px] leading-[24px] font-semibold;
}
.subtitle-1 {
@apply text-[16px] leading-[24px] font-medium;
}
.subtitle-2 {
@apply text-[14px] leading-[20px] font-semibold;
}
.body-1 {
@apply text-[16px] leading-[24px] font-normal;
}
.body-2 {
@apply text-[14px] leading-[20px] font-normal;
}
.button {
@apply text-[14px] leading-[20px] font-medium;
}
.caption {
@apply text-[12px] leading-[16px] font-normal;
}
.overline {
@apply text-[10px] leading-[14px] font-normal;
}
/* ===== HELPER CLASSES */
.container {
@apply mx-auto max-w-7xl px-5;
}
.primary-btn {
@apply bg-brand hover:bg-brand-100 transition-all rounded-full button !important;
}
.flex-center {
@apply flex items-center justify-center;
}
/* ===== SHADCN OVERRIDES */
.shad-no-focus {
@apply outline-none ring-offset-transparent focus:ring-transparent focus:ring-offset-0 focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-transparent focus-visible:ring-offset-0 !important;
}
.shad-input {
@apply border-none shadow-none p-0 shad-no-focus placeholder:text-light-200 body-2 !important;
}
.shad-form-item {
@apply flex h-[78px] flex-col justify-center rounded-xl border border-light-300 px-4 shadow-drop-1;
}
.shad-form-label {
@apply text-light-100 pt-2 body-2 w-full !important;
}
.shad-form-message {
@apply text-red body-2 ml-4 !important;
}
.shad-alert-dialog {
@apply space-y-4 max-w-[95%] sm:w-fit rounded-xl md:rounded-[30px] px-4 md:px-8 py-10 bg-white outline-none !important;
}
.shad-submit-btn {
@apply bg-brand button hover:bg-brand-100 transition-all rounded-full !important;
}
.shad-otp {
@apply w-full flex gap-1 sm:gap-2 justify-between !important;
}
.shad-otp-slot {
@apply text-[40px] font-medium rounded-xl ring-brand shadow-drop-1 text-brand-100 justify-center flex border-2 border-light-300 size-12 md:size-16 gap-5 !important;
}
.shad-sheet {
@apply pt-0 !important;
}
.shad-sheet button,
.shad-dialog button {
@apply focus:ring-0 focus:ring-offset-0 focus-visible:border-none outline-none focus-visible:outline-none focus-visible:ring-transparent focus-visible:ring-offset-0 !important;
}
.shad-dropdown-item {
@apply cursor-pointer !important;
}
.shad-dialog {
@apply rounded-[26px] w-[90%] max-w-[400px] px-6 py-8 !important;
}
.shad-chart-title {
@apply text-white !important;
}
.shad-select-item {
@apply cursor-pointer !important;
}
/* Sidebar & MobileNavigation */
.nav-icon {
@apply w-6 filter invert opacity-25 !important;
}
.nav-icon-active {
@apply invert-0 opacity-100 !important;
}
/* ===== STYLE CLASSES */
/* Root Layout */
.main-content {
@apply remove-scrollbar h-full flex-1 overflow-auto bg-light-400 px-5 py-7 sm:mr-7 sm:rounded-[30px] md:mb-7 md:px-9 md:py-10 !important;
}
/* Dashboard */
.dashboard-container {
@apply mx-auto grid max-w-7xl grid-cols-1 gap-6 md:grid-cols-2 xl:gap-10 !important;
}
.dashboard-summary-list {
@apply mt-6 grid grid-cols-1 gap-4 xl:mt-10 xl:grid-cols-2 xl:gap-9 !important;
}
.dashboard-summary-card {
@apply relative mt-6 rounded-[20px] bg-white p-5 transition-all hover:scale-105 !important;
}
.summary-type-icon {
@apply absolute -left-3 top-[-25px] z-10 w-[190px] object-contain !important;
}
.summary-type-size {
@apply h4 relative z-20 w-full text-right !important;
}
.summary-type-title {
@apply h5 relative z-20 text-center !important;
}
.dashboard-recent-files {
@apply h-full rounded-[20px] xl:h-[654px] custom-scrollbar overflow-auto bg-white p-5 xl:p-7 !important;
}
.recent-file-details {
@apply flex w-full justify-between items-center !important;
}
.recent-file-name {
@apply subtitle-2 line-clamp-1 w-full text-light-100 sm:max-w-[200px] lg:max-w-[250px] !important;
}
.recent-file-date {
@apply body-2 text-light-100/80 !important;
}
.empty-list {
@apply body-1 mt-10 text-center text-light-200 !important;
}
/* Type page */
.page-container {
@apply mx-auto flex w-full max-w-7xl flex-col items-center gap-8 !important;
}
.total-size-section {
@apply flex mt-2 flex-col justify-between sm:flex-row sm:items-center !important;
}
.file-list {
@apply grid w-full gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 !important;
}
.sort-container {
@apply mt-5 flex items-center sm:mt-0 sm:gap-3 !important;
}
/* ActionsDropdown */
.rename-input-field {
@apply body-2 shad-no-focus h-[52px] w-full rounded-full border px-4 shadow-drop-1 !important;
}
.delete-confirmation {
@apply text-center text-light-100 !important;
}
.delete-file-name {
@apply font-medium text-brand-100 !important;
}
.modal-cancel-button {
@apply h-[52px] flex-1 rounded-full bg-white text-light-100 hover:bg-transparent !important;
}
.modal-submit-button {
@apply primary-btn !mx-0 h-[52px] w-full flex-1 !important;
}
/* ActionsModalContent */
.file-details-thumbnail {
@apply !mb-1 flex items-center gap-3 rounded-xl border border-light-200/40 bg-light-400/50 p-3 !important;
}
.file-details-label {
@apply body-2 w-[30%] text-light-100 !important;
}
.file-details-value {
@apply subtitle-2 flex-1 !important;
}
.share-wrapper {
@apply !mt-2 space-y-2 !important;
}
.share-input-field {
@apply body-2 shad-no-focus h-[52px] w-full rounded-full border px-4 shadow-drop-1 !important;
}
.share-remove-user {
@apply rounded-full bg-transparent text-light-100 shadow-none hover:bg-transparent !important;
}
.remove-icon {
@apply aspect-square rounded-full !important;
}
/* AuthForm */
.auth-form {
@apply flex max-h-[800px] w-full max-w-[580px] flex-col justify-center space-y-6 transition-all lg:h-full lg:space-y-8 !important;
}
.form-title {
@apply h1 text-center text-light-100 md:text-left !important;
}
.form-submit-button {
@apply primary-btn h-[66px] !important;
}
.error-message {
@apply body-2 mx-auto w-fit rounded-xl bg-error/5 px-8 py-4 text-center text-error !important;
}
/* Card */
.file-card {
@apply flex cursor-pointer flex-col gap-6 rounded-[18px] bg-white p-5 shadow-sm transition-all hover:shadow-drop-3 !important;
}
.file-card-details {
@apply flex flex-col gap-2 text-light-100 !important;
}
/* Chart */
.chart {
@apply flex items-center rounded-[20px] bg-brand p-2 text-white md:flex-col xl:flex-row !important;
}
.chart-container {
@apply mx-auto aspect-square w-[180px] text-white xl:w-[200px] !important;
}
.polar-grid {
@apply first:fill-white/20 last:fill-brand !important;
}
.chart-details {
@apply flex-1 items-start px-3 py-0 sm:px-5 lg:p-3 xl:pr-5 !important;
}
.chart-total-percentage {
@apply fill-white text-4xl font-bold !important;
}
.chart-title {
@apply h3 font-bold md:text-center lg:text-left !important;
}
.chart-description {
@apply subtitle-1 mt-2 w-full text-white/70 md:text-center lg:text-left !important;
}
/* FileUploader */
.uploader-button {
@apply primary-btn h-[52px] gap-2 px-10 shadow-drop-1 !important;
}
.uploader-preview-list {
@apply fixed bottom-10 right-10 z-50 flex size-full h-fit max-w-[480px] flex-col gap-3 rounded-[20px] bg-white p-7 shadow-drop-3 !important;
}
.uploader-preview-item {
@apply flex items-center justify-between gap-3 rounded-xl p-3 shadow-drop-3 !important;
}
.preview-item-name {
@apply subtitle-2 mb-2 line-clamp-1 max-w-[300px] !important;
}
.error-toast {
@apply bg-red !rounded-[10px] !important;
}
/* Header */
.header {
@apply hidden items-center justify-between gap-5 p-5 sm:flex lg:py-7 xl:gap-10 !important;
}
.header-wrapper {
@apply flex-center min-w-fit gap-4 !important;
}
.sign-out-button {
@apply flex-center h-[52px] min-w-[54px] items-center rounded-full bg-brand/10 p-0 text-brand shadow-none transition-all hover:bg-brand/20 !important;
}
/* Mobile Navigation */
.mobile-header {
@apply flex h-[60px] justify-between px-5 sm:hidden !important;
}
.header-user {
@apply my-3 flex items-center gap-2 rounded-full p-1 text-light-100 sm:justify-center sm:bg-brand/10 lg:justify-start lg:p-3 !important;
}
.header-user-avatar {
@apply aspect-square w-10 rounded-full object-cover !important;
}
.mobile-nav {
@apply h5 flex-1 gap-1 text-brand !important;
}
.mobile-nav-list {
@apply flex flex-1 flex-col gap-4 !important;
}
.mobile-nav-item {
@apply flex text-light-100 gap-4 w-full justify-start items-center h5 px-6 h-[52px] rounded-full !important;
}
.mobile-sign-out-button {
@apply h5 flex h-[52px] w-full items-center gap-4 rounded-full bg-brand/10 px-6 text-brand shadow-none transition-all hover:bg-brand/20 !important;
}
/* OTP Modal */
.otp-close-button {
@apply absolute -right-1 -top-7 cursor-pointer sm:-right-2 sm:-top-4 !important;
}
/* Search */
.search {
@apply relative w-full md:max-w-[480px] !important;
}
.search-input-wrapper {
@apply flex h-[52px] flex-1 items-center gap-3 rounded-full px-4 shadow-drop-3 !important;
}
.search-input {
@apply body-2 shad-no-focus placeholder:body-1 w-full border-none p-0 shadow-none placeholder:text-light-200 !important;
}
.search-result {
@apply absolute left-0 top-16 z-50 flex w-full flex-col gap-3 rounded-[20px] bg-white p-4 !important;
}
.empty-result {
@apply body-2 text-center text-light-100 !important;
}
/* Sidebar */
.sidebar {
@apply remove-scrollbar hidden h-screen w-[90px] flex-col overflow-auto px-5 py-7 sm:flex lg:w-[280px] xl:w-[325px] !important;
}
.sidebar-nav {
@apply h5 mt-9 flex-1 gap-1 text-brand !important;
}
.sidebar-nav-item {
@apply flex text-light-100 gap-4 rounded-xl lg:w-full justify-center lg:justify-start items-center h5 lg:px-[30px] h-[52px] lg:rounded-full !important;
}
.sidebar-user-info {
@apply mt-4 flex items-center justify-center gap-2 rounded-full bg-brand/10 p-1 text-light-100 lg:justify-start lg:p-3 !important;
}
.sidebar-user-avatar {
@apply aspect-square w-10 rounded-full object-cover !important;
}
.shad-active {
@apply bg-brand text-white shadow-drop-2 !important;
}
/* Sort */
.sort-select {
@apply shad-no-focus h-11 w-full rounded-[8px] border-transparent bg-white !shadow-sm sm:w-[210px] !important;
}
.sort-select-content {
@apply !shadow-drop-3 !important;
}
/* Thumbnail */
.thumbnail {
@apply flex-center size-[50px] min-w-[50px] overflow-hidden rounded-full bg-brand/10;
}
.thumbnail-image {
@apply size-full object-cover object-center !important;
}
}
```
</details>
<details>
<summary><code>constants/index.ts</code></summary>
```typescript
export const navItems = [
{
name: 'Dashboard',
icon: '/assets/icons/dashboard.svg',
url: '/',
},
{
name: 'Documents',
icon: '/assets/icons/documents.svg',
url: '/documents',
},
{
name: 'Images',
icon: '/assets/icons/images.svg',
url: '/images',
},
{
name: 'Media',
icon: '/assets/icons/video.svg',
url: '/media',
},
{
name: 'Others',
icon: '/assets/icons/others.svg',
url: '/others',
},
];
export const actionsDropdownItems = [
{
label: 'Rename',
icon: '/assets/icons/edit.svg',
value: 'rename',
},
{
label: 'Details',
icon: '/assets/icons/info.svg',
value: 'details',
},
{
label: 'Share',
icon: '/assets/icons/share.svg',
value: 'share',
},
{
label: 'Download',
icon: '/assets/icons/download.svg',
value: 'download',
},
{
label: 'Delete',
icon: '/assets/icons/delete.svg',
value: 'delete',
},
];
export const sortTypes = [
{
label: 'Date created (newest)',
value: '$createdAt-desc',
},
{
label: 'Created Date (oldest)',
value: '$createdAt-asc',
},
{
label: 'Name (A-Z)',
value: 'name-asc',
},
{
label: 'Name (Z-A)',
value: 'name-desc',
},
{
label: 'Size (Highest)',
value: 'size-desc',
},
{
label: 'Size (Lowest)',
value: 'size-asc',
},
];
export const MAX_FILE_SIZE = 50 * 1024 * 1024; // 50MB
```
</details>
<details>
<summary><code>lib/utils.ts</code></summary>
```typescript
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const parseStringify = (value: unknown) =>
JSON.parse(JSON.stringify(value));
export const convertFileToUrl = (file: File) => URL.createObjectURL(file);
export const convertFileSize = (sizeInBytes: number, digits?: number) => {
if (sizeInBytes < 1024) {
return sizeInBytes + ' Bytes'; // Less than 1 KB, show in Bytes
} else if (sizeInBytes < 1024 * 1024) {
const sizeInKB = sizeInBytes / 1024;
return sizeInKB.toFixed(digits || 1) + ' KB'; // Less than 1 MB, show in KB
} else if (sizeInBytes < 1024 * 1024 * 1024) {
const sizeInMB = sizeInBytes / (1024 * 1024);
return sizeInMB.toFixed(digits || 1) + ' MB'; // Less than 1 GB, show in MB
} else {
const sizeInGB = sizeInBytes / (1024 * 1024 * 1024);
return sizeInGB.toFixed(digits || 2) + ' GB'; // 1 GB or more, show in GB
}
};
export const calculateAngle = (sizeInBytes: number) => {
const totalSizeInBytes = 2 * 1024 * 1024 * 1024; // 2GB in bytes
const percentage = (sizeInBytes / totalSizeInBytes) * 360;
return Number(percentage.toFixed(2));
};
export const calculatePercentage = (sizeInBytes: number) => {
const totalSizeInBytes = 2 * 1024 * 1024 * 1024; // 2GB in bytes
const percentage = (sizeInBytes / totalSizeInBytes) * 100;
return Number(percentage.toFixed(1));
};
export const getFileType = (fileName: string) => {
const extension = fileName.split('.').pop()?.toLowerCase();
if (!extension) return { type: 'other', extension: '' };
const documentExtensions = [
'pdf',
'doc',
'docx',
'txt',
'xls',
'xlsx',
'csv',
'rtf',
'ods',
'ppt',
'odp',
'md',
'html',
'htm',
'epub',
'pages',
'fig',
'psd',
'ai',
'indd',
'xd',
'sketch',
'afdesign',
'afphoto',
'afphoto',
];
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp'];
const videoExtensions = ['mp4', 'avi', 'mov', 'mkv', 'webm'];
const audioExtensions = ['mp3', 'wav', 'ogg', 'flac'];
if (documentExtensions.includes(extension))
return { type: 'document', extension };
if (imageExtensions.includes(extension)) return { type: 'image', extension };
if (videoExtensions.includes(extension)) return { type: 'video', extension };
if (audioExtensions.includes(extension)) return { type: 'audio', extension };
return { type: 'other', extension };
};
export const formatDateTime = (isoString: string | null | undefined) => {
if (!isoString) return '—';
const date = new Date(isoString);
// Get hours and adjust for 12-hour format
let hours = date.getHours();
const minutes = date.getMinutes();
const period = hours >= 12 ? 'pm' : 'am';
// Convert hours to 12-hour format
hours = hours % 12 || 12;
// Format the time and date parts
const time = `${hours}:${minutes.toString().padStart(2, '0')}${period}`;
const day = date.getDate();
const monthNames = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
const month = monthNames[date.getMonth()];
return `${time}, ${day} ${month}`;
};
export const getFileIcon = (
extension: string | undefined,
type: FileType | string,
) => {
switch (extension) {
// Document
case 'pdf':
return '/assets/icons/file-pdf.svg';
case 'doc':
return '/assets/icons/file-doc.svg';
case 'docx':
return '/assets/icons/file-docx.svg';
case 'csv':
return '/assets/icons/file-csv.svg';
case 'txt':
return '/assets/icons/file-txt.svg';
case 'xls':
case 'xlsx':
return '/assets/icons/file-document.svg';
// Image
case 'svg':
return '/assets/icons/file-image.svg';
// Video
case 'mkv':
case 'mov':
case 'avi':
case 'wmv':
case 'mp4':
case 'flv':
case 'webm':
case 'm4v':
case '3gp':
return '/assets/icons/file-video.svg';
// Audio
case 'mp3':
case 'mpeg':
case 'wav':
case 'aac':
case 'flac':
case 'ogg':
case 'wma':
case 'm4a':
case 'aiff':
case 'alac':
return '/assets/icons/file-audio.svg';
default:
switch (type) {
case 'image':
return '/assets/icons/file-image.svg';
case 'document':
return '/assets/icons/file-document.svg';
case 'video':
return '/assets/icons/file-video.svg';
case 'audio':
return '/assets/icons/file-audio.svg';
default:
return '/assets/icons/file-other.svg';
}
}
};
// APPWRITE URL UTILS
// Construct appwrite file URL - https://appwrite.io/docs/apis/rest#images
export const constructFileUrl = (bucketFileId: string) => {
return `${process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT}/storage/buckets/${process.env.NEXT_PUBLIC_APPWRITE_BUCKET}/files/${bucketFileId}/view?project=${process.env.NEXT_PUBLIC_APPWRITE_PROJECT}`;
};
export const constructDownloadUrl = (bucketFileId: string) => {
return `${process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT}/storage/buckets/${process.env.NEXT_PUBLIC_APPWRITE_BUCKET}/files/${bucketFileId}/download?project=${process.env.NEXT_PUBLIC_APPWRITE_PROJECT}`;
};
// DASHBOARD UTILS
export const getUsageSummary = (totalSpace: any) => {
return [
{
title: 'Documents',
size: totalSpace.document.size,
latestDate: totalSpace.document.latestDate,
icon: '/assets/icons/file-document-light.svg',
url: '/documents',
},
{
title: 'Images',
size: totalSpace.image.size,
latestDate: totalSpace.image.latestDate,
icon: '/assets/icons/file-image-light.svg',
url: '/images',
},
{
title: 'Media',
size: totalSpace.video.size + totalSpace.audio.size,
latestDate:
totalSpace.video.latestDate > totalSpace.audio.latestDate
? totalSpace.video.latestDate
: totalSpace.audio.latestDate,
icon: '/assets/icons/file-video-light.svg',
url: '/media',
},
{
title: 'Others',
size: totalSpace.other.size,
latestDate: totalSpace.other.latestDate,
icon: '/assets/icons/file-other-light.svg',
url: '/others',
},
];
};
export const getFileTypesParams = (type: string) => {
switch (type) {
case 'documents':
return ['document'];
case 'images':
return ['image'];
case 'media':
return ['video', 'audio'];
case 'others':
return ['other'];
default:
return ['document'];
}
};
```
</details>
<details>
<summary><code>index.d.ts</code></summary>
```ts
/* eslint-disable no-unused-vars */
declare type FileType = 'document' | 'image' | 'video' | 'audio' | 'other';
declare interface ActionType {
label: string;
icon: string;
value: string;
}
declare interface SearchParamProps {
params?: Promise<SegmentParams>;
searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;
}
declare interface UploadFileProps {
file: File;
ownerId: string;
accountId: string;
path: string;
}