Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshj01 committed Jun 17, 2024
1 parent 8e486df commit 6ee1ccf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/app/(main)/_components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const Preview = ({ logId }: { logId: string }) => {
const [copied, setCopied] = useState<boolean>(false);
const [previewLog, setpreviewLog] = useState<Log | null>(null);
const { theme } = useTheme();
const router = useRouter();
const pathName = usePathname()
const isPublishRoute = pathName.includes('/logs/publish');
const { isOpen, onOpen, onClose } = useDisclosure();
Expand Down
8 changes: 6 additions & 2 deletions src/app/(main)/_components/SideBarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const SidebarItem: React.FC<SidebarItemProps> = ({ selected, id, log, onLogClick
const { isOpen, onOpen, onClose } = useDisclosure();

function MoreOptions() {
const options = ['Share', 'Delete'];
const options = ['Share', 'Delete', 'Delete Local'];

return (<PSDropdown
options={options}
onClick={handleonAction}
className="custom-dropdown-class">
className="dropdown-class">
<EllipsisHorizontalIcon
className='h-5 w-7 cursor-pointer transition-all duration-100' />
</PSDropdown>
Expand All @@ -49,6 +49,10 @@ const SidebarItem: React.FC<SidebarItemProps> = ({ selected, id, log, onLogClick
const logService = new LogService();
switch (key) {
case '1':
await logService.deleteLogById(id);
onRefresh();
break;
case '2':
await logService.deleteLogFromLocal(id);
onRefresh();
break;
Expand Down
20 changes: 17 additions & 3 deletions src/app/(main)/_services/logService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// src/services/LogService.ts

import { addDoc, collection, doc, getDoc, getDocs, updateDoc } from 'firebase/firestore';
import { addDoc, collection, deleteDoc, doc, getDoc, getDocs, updateDoc } from 'firebase/firestore';
import { db } from '../../../utils/firebase';
import { Log } from '../_models/Log';

Expand Down Expand Up @@ -38,15 +38,17 @@ class LogService {
try {
const docRef = await addDoc(this.logCollection, log.toFirestore());
if (docRef.id) {
console.log("published at", docRef.id);
await this.saveLogToLocal({
...log, id: docRef.id,
toFirestore: function () {
throw new Error('Function not implemented.');
}
});
return docRef.id;
return docRef.id!
}
return '';
console.log("publish failed");
return await this.fetchLogFromLocalById(docRef.id) ? docRef.id : '';
} catch (e) {
return '';
}
Expand All @@ -58,6 +60,18 @@ class LogService {
await this.saveLogToLocal(log);
}

async markExpiredById(id: string): Promise<void> {
const docRef = doc(this.logCollection, id);
await updateDoc(docRef, { isExpired: true });
await this.deleteLogFromLocal(id);
}

async deleteLogById(id: string): Promise<void> {
const docRef = doc(this.logCollection, id);
await deleteDoc(docRef);
await this.deleteLogFromLocal(id);
}

async deleteExpiredLogs(): Promise<void> {
const querySnapshot = await getDocs(this.logCollection);
const updatePromises: Promise<void>[] = [];
Expand Down
1 change: 1 addition & 0 deletions src/app/(publish)/logs/publish/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const dynamicParams = true;
export async function generateStaticParams() {
const logService = new LogService();
const logs = await logService.fetchLogs();
// logs.forEach(log => console.log(log.id));
return logs.map(log => ({ id: log.id }));
}
export default function PublishPage({ params }: { params: { id: string } }) {
Expand Down

0 comments on commit 6ee1ccf

Please sign in to comment.