|
1 | 1 | import { decrypt } from '@metamask/browser-passworder'; |
2 | | -import { DocumentReference, arrayRemove, updateDoc } from 'firebase/firestore'; |
| 2 | +import { DocumentReference, arrayRemove, arrayUnion, updateDoc } from 'firebase/firestore'; |
3 | 3 | import { useCallback, useContext, useEffect, useMemo, useState } from 'react'; |
4 | | -import { FaTimes } from 'react-icons/fa'; |
| 4 | +import { FaArchive, FaTimes } from 'react-icons/fa'; |
5 | 5 | import { toast } from 'react-toastify'; |
6 | 6 | import { twJoin } from 'tailwind-merge'; |
7 | 7 | import { TOTP } from 'totp-generator'; |
@@ -120,11 +120,14 @@ export function TokenCard({ |
120 | 120 | } |
121 | 121 | }, [hidden, token]); |
122 | 122 |
|
| 123 | + if (data.archived && !editMode) return null; |
| 124 | + |
123 | 125 | return ( |
124 | 126 | <div |
125 | 127 | className={twJoin( |
126 | 128 | 'p-3 bg-slate-800 border border-slate-700 rounded-md select-none flex gap-6 justify-between items-center hover:brightness-[90%] relative cursor-pointer transition-all rotate-0', |
127 | | - editMode && 'animate-wiggle' |
| 129 | + editMode && 'animate-wiggle', |
| 130 | + data.archived && 'opacity-50' |
128 | 131 | )} |
129 | 132 | style={{ animationDelay: `${Math.random() * 250}ms` }} |
130 | 133 | tabIndex={0} |
@@ -154,6 +157,35 @@ export function TokenCard({ |
154 | 157 | </div> |
155 | 158 | </div> |
156 | 159 |
|
| 160 | + <button |
| 161 | + className="remove absolute -top-3 right-6 !p-1 text-slate-800 bg-white border border-slate-400 rounded-full sm:hover:bg-warning transition-all duration-300" |
| 162 | + style={{ pointerEvents: editMode ? 'auto' : 'none', opacity: editMode ? 1 : 0 }} |
| 163 | + tabIndex={editMode ? 0 : -1} |
| 164 | + onClick={async (e) => { |
| 165 | + e.stopPropagation(); |
| 166 | + |
| 167 | + const confirm = window.confirm( |
| 168 | + `Are you sure you want to ${data.archived ? 'unarchive' : 'archive'} ${data.name}?` |
| 169 | + ); |
| 170 | + if (confirm) { |
| 171 | + // Remove old key |
| 172 | + await updateDoc(userRef, { |
| 173 | + keys: arrayRemove({ name: data.name, secret: data.secret, archived: data.archived }), |
| 174 | + }); |
| 175 | + |
| 176 | + // Add new key with updated archived status |
| 177 | + await updateDoc(userRef, { |
| 178 | + keys: arrayUnion({ name: data.name, secret: data.secret, archived: !data.archived }), |
| 179 | + }); |
| 180 | + } |
| 181 | + }} |
| 182 | + onMouseDown={(e) => e.stopPropagation()} |
| 183 | + onTouchStart={(e) => e.stopPropagation()} |
| 184 | + onPointerDown={(e) => e.stopPropagation()} |
| 185 | + > |
| 186 | + <FaArchive /> |
| 187 | + </button> |
| 188 | + |
157 | 189 | <button |
158 | 190 | className="remove absolute -top-3 -right-3 !p-1 text-slate-800 bg-white border border-slate-400 rounded-full hover:text-white sm:hover:bg-danger transition-all duration-300" |
159 | 191 | style={{ pointerEvents: editMode ? 'auto' : 'none', opacity: editMode ? 1 : 0 }} |
|
0 commit comments