Skip to content

Commit

Permalink
Added backup data option
Browse files Browse the repository at this point in the history
  • Loading branch information
codeAbinash committed Jun 23, 2023
1 parent ab55f8d commit 54d39e0
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 71 deletions.
9 changes: 4 additions & 5 deletions public/changelog/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
],
"date": "2023-06-23",
"description": [
"Added Messages",
"Improved overall performance"
"Improved overall performance."
]
},
{
Expand All @@ -22,8 +21,8 @@
],
"date": "2023-06-23",
"description": [
"Added All routines popup view",
"Improved performance of the app"
"Added All routines popup view.",
"Improved performance of the app."
]
},
{
Expand All @@ -35,7 +34,7 @@
],
"date": "2023-06-22",
"description": [
"Performance improvements of the Routine popup view"
"Performance improvements of the Routine popup view."
]
},
{
Expand Down
5 changes: 4 additions & 1 deletion public/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const cacheData = {
static: {
name: 'routine-static-files-routine-v1',
valid: 'routine-static-files-routine',
urls: [],
urls: [
// While loading don't load the spinner 😆🤣
'https://codeabinash.github.io/routine/assets/spinner.svg'
],
},
}

Expand Down
5 changes: 4 additions & 1 deletion src/assets/icons/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import spinner from './src/spinner.svg'
import chat from './src/chat.svg'
import del from './src/delete.svg'
import edit from './src/edit.svg'
import telegram from './src/telegram.svg'
import backup_folder from './src/backup_folder.webp'


const icons = {
Lock, delete_left_solid, home,
Expand All @@ -40,7 +43,7 @@ const icons = {
check_solid, xmark_solid, notification,
right_arrow_next, shield, theme, left_arrow,
backup, restore, shield_cross, telegram_black,
spinner, chat, del, edit
spinner, chat, del, edit, telegram, backup_folder
}


Expand Down
Binary file added src/assets/icons/src/backup_folder.webp
Binary file not shown.
1 change: 1 addition & 0 deletions src/assets/icons/src/telegram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion src/assets/scss/common/_classes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,14 @@ button.btn-full-width.grey {
// 100% {
// transform: skewX(-3deg) scale(0.9) skewY(-5deg);
// }
// }
// }


.scrollbar-hidden::-webkit-scrollbar {
display: none;
}

.scrollbar-hidden {
-ms-overflow-style: none;
scrollbar-width: none;
}
9 changes: 6 additions & 3 deletions src/components/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import icons from "../assets/icons/icons"
import { useNavigate } from "react-router-dom"
import delay, { df } from "../lib/delay"
const tabIcons = [icons.home, icons.routines, icons.calendar, icons.chat, icons.more]
const tabs = ['Home', 'Routines', 'Calendar', 'Messages', 'More']
const links = ['/', '/routines', '/calendar', '/messages', '/more']
const tabIcons = [icons.home, icons.routines, icons.calendar, icons.more]
const tabs = ['Home', 'Routines', 'Calendar', 'More']
const links = ['/', '/routines', '/calendar', '/more']
// const tabIcons = [icons.home, icons.routines, icons.calendar, icons.chat, icons.more]
// const tabs = ['Home', 'Routines', 'Calendar', 'Messages', 'More']
// const links = ['/', '/routines', '/calendar', '/messages', '/more']

function NavBar({ active }: { active: 'Home' | 'Routines' | 'Messages' | 'Calendar' | 'More' }) {
const navigate = useNavigate()
Expand Down
19 changes: 11 additions & 8 deletions src/components/TextEmoji.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import Emoji from "emoji-store"
let e = new Emoji({
let e_apple = new Emoji({
author: 'apple',
size: 160,
type: 'png'
})

let e_facebook = new Emoji({
author: 'facebook',
size: 96,
type: 'png'
})


type EmojiType = {
emoji: string,
type?: 'apple' | 'facebook'
}

export default function TextEmoji({ emoji, type }: EmojiType) {
let em = e
let em = e_apple
if (type == 'facebook')
em = new Emoji({
author: 'facebook',
size: 96,
type: 'png'
})
return <img src={em.get(emoji)} alt="" className="inline-block h-[1.3em] align-middle" />
em = e_facebook
return <img src={em.get(emoji)} alt={emoji} loading="lazy" className="inline-block h-[1.3em] align-middle" />
}
62 changes: 48 additions & 14 deletions src/pages/More.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function More() {
{
name: 'Backup your data',
icon: icons.backup,
callback: () => navigate('/backup'),
callback: () => { navigate('/backup') },
rightArrow: true
},
{
Expand Down Expand Up @@ -110,10 +110,32 @@ function More() {
{
name: 'Join Telegram Channel',
icon: icons.telegram_black,
callback: () => window.open('https://t.me/routine_application', '_blank'),
callback: () => {
setModalUi(JoinTelegramUi)
setIsShow(true)
setModalButtons(['Cancel', 'Join'])
setModalCallbacks([() => { setIsShow(false) },
() => window.open('https://t.me/routine_application', '_blank')
])
},
rightArrow: true,
newDot: true
},
{
name: 'Send Feedback',
icon: icons.chat,

callback: () => {
setModalUi(FeedBackUi)
setIsShow(true)
setModalButtons(['Cancel', 'Send Feedback'])
setModalCallbacks([() => { setIsShow(false) },
() =>
window.open('mailto:[email protected]?subject=Feedback of Routine Application', '_blank')
])
},
rightArrow: true
},
{
name: 'Contributors',
icon: icons.team,
Expand All @@ -123,14 +145,6 @@ function More() {
rightArrow: true,
// iconOriginal : true
},
{
name: 'Send Feedback',
icon: icons.chat,
callback: () => {
window.open('mailto:[email protected]?subject=Feedback of Routine Application', '_blank')
},
rightArrow: true
}
]

const navigate = useNavigate()
Expand Down Expand Up @@ -223,8 +237,28 @@ export default More

function ResetEverythingUI() {
return <>
<p className='text-center text-xl font-semibold'>Are you sure you want to reset everything?</p>
<div className='animate-bounce-slow mt-10 mb-10'><img src={Emoji.get('🤯')} alt="bag" className={`mx-auto mt-5 w-24 h-24`} /></div>
<p className='text-center text-grey text-xs mt-5 font-[450]'>This will delete all your routines, subscriptions, and settings. <br />This action cannot be undone.</p>
<p className='text-center text-xl font-semibold text-balance'>Are you sure you want to reset everything?</p>
<div className='animate-bounce-slow mt-10 mb-10 '><img src={Emoji.get('🤯')} alt="bag" className={`mx-auto mt-5 w-24 h-24`} /></div>
<p className='text-center text-grey text-xs mt-5 font-[450] text-balance'>It is advised to keep a backup before resetting everything. This will delete all your routines, subscriptions, and settings. This action cannot be undone. Are you sure?</p>
</>
}

function JoinTelegramUi() {
return <>
<p className='text-center text-xl font-semibold text-balance'>Join Telegram channel to get latest updates <TextEmoji emoji='🤩' /> </p>
<div className='animate-bounce-slow mt-10 mb-10 '><img src={icons.telegram} alt="bag" className={`mx-auto mt-5 w-28 h-28`} /></div>
<p className='text-center text-grey text-xs mt-5 font-[450] text-balance'>
Join Telegram Channel <a href="https://t.me/routine_application" target='_blank' className='text-accent'>routine_application</a> to get latest updates about this application.
</p>
</>
}
}
function FeedBackUi() {
return <>
<p className='text-center text-xl font-semibold text-balance'>Send Feedback <TextEmoji emoji='🤩' /> </p>
<div className='animate-bounce-slow mt-10 mb-10 '><img src={icons.chat} alt="bag" className={`mx-auto mt-5 w-24 h-24`} /></div>
<p className='text-center text-grey text-xs mt-5 font-[450] text-balance'>
Your feedback is valuable. Please send your feedback to <a href="mailto:[email protected]?subject=Feedback of Routine Application" target='_blank' className='text-accent'>
[email protected]</a>
</p>
</>
}
11 changes: 9 additions & 2 deletions src/pages/NewRoutine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Weekly from './makeRoutine/Weekly';
import TextEmoji from '../components/TextEmoji';
import BottomModal, { BasicModal } from '../components/BottomModal';
import { MODAL_BUTTON_TEXT } from '../lib/lib';
let emojiList = ['📕', '🧑🏻‍💻', '🏃🏻‍♂️', '🎨', '👻']
let emojiList = ['📕', '🧑🏻‍💻', '🏃🏻‍♂️', '🍽️', '🏫', '🧪', '🎂', '📖', '👩🏻‍🔬', '🎶']

function NewRoutine() {
const e = new Emoji();
Expand All @@ -23,6 +23,7 @@ function NewRoutine() {
const [routine, setRoutine] = useState<any>({})
const navigate = useNavigate()
const topElement: any = useRef<HTMLDivElement>()
const emojiInput = useRef<any>(null)

const [modalShow, setModalShow] = useState(false)
const [modalBtnText, setModalBtnText] = useState(MODAL_BUTTON_TEXT)
Expand Down Expand Up @@ -98,6 +99,7 @@ function NewRoutine() {
placeholder='Emoji'
className='name input-text bg-inputBg dark:bg-darkInputBg flex-1'
onInput={(e: any) => { setRoutineEmoji(e.target.value) }}
ref={emojiInput}
/>
<select defaultValue={routineType} onInput={(e: any) => setRoutineType(e.target.value)} className='flex-[4] appearance-none p-[1rem] px-7 rounded-2xl trans-outline outline-none focus:outline-accent border-none bg-inputBg dark:bg-darkInputBg text-center'>
<option value="once">Routine : Once</option>
Expand All @@ -110,13 +112,18 @@ function NewRoutine() {
</select>
{/* <img src={e.get('➕')} className='tap bg-inputBg dark:bg-darkInputBg h-[3.5rem] p-[0.8rem] rounded-2xl' /> */}
</div></div>
<div className="emojis flex gap-3 rounded-2xl flex-wrap justify-between items-center">
<div className="emojis flex gap-3 scrollbar-hidden flex-nowrap overflow-auto justify-between items-center">
{emojiList.map((emoji, index) =>
<img src={e.get(emoji)}
onClick={() => setRoutineEmoji(emoji)}
className='tap bg-inputBg dark:bg-darkInputBg h-[3.2rem] p-[0.8rem] rounded-2xl' key={index}
/>
)}
<p className='tap bg-inputBg dark:bg-darkInputBg h-[3.2rem] p-[0.8rem] rounded-2xl aspect-square flex justify-center items-center text-2xl'
onClick={() => {
emojiInput && emojiInput.current.focus()
}}
>+</p>
</div>
{RoutineMaker(routineType)}
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/TestPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { BackupUi } from './More'

export default function TestPage() {
const modalRef = React.useRef<HTMLDialogElement>(null)
Expand All @@ -9,6 +10,7 @@ export default function TestPage() {
// }
}, [])

return <BackupUi />

return (
<>
Expand Down
80 changes: 50 additions & 30 deletions src/pages/backup-restore/Backup.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,70 @@
import { useState } from 'react'
import images from '../../assets/images/images'
import BackHeader from '../../components/BackHeader'
import icons from '../../assets/icons/icons'
import ls from '../../lib/storage'
import TextEmoji from '../../components/TextEmoji'

function Backup() {
const [isBackedUp, setBackedUp] = useState(false)
const [backupBtnText, setBackupBtnText] = useState('Backup Now')


return (
<div className='backup screen dark:text-darkText'>
<BackHeader title='Backup your data' />
<section className='p-5 flex flex-col justify-center items-center pt-16'>
<img src={images.undraw_add_notes_re_ln36} className='w-[70%] m-auto mt-10' />
<p className='mt-8 text-xs px-3 pt-2 text-center'>Back up your data by downloading the file. Keep it safe and use it when you next use this application or switch devices. </p>
{!isBackedUp && <button onClick={() => backup()} className='no-highlight tap97 mt-5 bg-accent p-4 px-9 text-xs text-white font-medium rounded-full'>{backupBtnText}</button>}
</section>
{
isBackedUp && <BackUpSection />
}
<div className='min-h-[80dvh] p-5 flex flex-col justify-center items-center gap-7'>
<p className='text-center text-xl font-semibold text-balance'>Backup your data <TextEmoji emoji='📂' /> </p>

<img src={icons.backup_folder} className='w-[45%] mx-auto drop-shadow-2xl' />
<p className='text-balance text-[0.65rem] text-center text-secondary'>
You can backup your data by downloading a file. This file can be used to restore your data on another device. Or you can use it to restore your data if you reinstall the app.
</p>
<BackupUi />
</div>
</div>
)
function backup() {
setBackupBtnText('Backing up...')
// Write Backup Code Here
setTimeout(() => {
setBackedUp(true)
setBackupBtnText('Backup Again')
}, 1000);
}
export function BackupUi() {
const [isBackingUp, setIsBackingUp] = useState(false)
const [isBackedUp, setIsBackedUp] = useState(false)

function backupBtnClick() {
setIsBackingUp(true)
setTimeout(() => {
setBackedUp(false)
}, 5000);
createBackup()
setIsBackingUp(false)
setIsBackedUp(true)
}, 500);
}
}

function BackUpSection() {
return (
<div className="p-5">
<p className='text-xs text-center'>Your data has been backed up successfully.</p>
<div className='flex flex-col gap-2 mt-5'>
<button className='btn-full text-sm no-highlight tap99'>Download 2281416.json</button>
</div>
return <>
{/* <div className='animate-bounce-slow mt-10 mb-10 '><img src={icons.backup} alt="bag" className={`mx-auto mt-5 w-24 h-24`} /></div> */}
<div className='flex justify-center items-center pt-10'>
<button className="no-highlight tap99 bg-dark text-white p-4 px-14 font-medium rounded-[0.65rem] text-xs"
disabled={isBackingUp}
onClick={backupBtnClick}
>
{
isBackingUp ? 'Preparing Backup...' : isBackedUp ? 'Backup Again' : 'Download Backup'
}
</button>
</div>
)
<p className='text-center text-grey text-[0.65rem] mt-5 text-balance'>This will download a backup file containing all your data. </p>
</>
}

function createBackup() {
const routines = JSON.parse(ls.get('routines') || '[]')
const subscriptions = JSON.parse(ls.get('subscriptions') || '[]')

const backup = { routines, subscriptions }

const dataStr = JSON.stringify(backup)
const blob = new Blob([dataStr], { type: "text/plain;charset=utf-8" });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'routine_backup.json';
a.click();
a.remove()
window.URL.revokeObjectURL(url);
}

export default Backup
1 change: 0 additions & 1 deletion src/pages/makeRoutine/Daily.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ function Daily({ updateRoutine }: { updateRoutine: Function }) {
const [endTime, setEndTime] = React.useState('')
useEffect(() => {
const routine = { time: [startTime, endTime] }
console.log(routine)
updateRoutine(routine)
}, [startTime, endTime])

Expand Down
Loading

0 comments on commit 54d39e0

Please sign in to comment.