mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 17:21:35 +10:00
Add PDF file caching
This commit is contained in:
@ -13,6 +13,7 @@ import {
|
||||
} from '@mui/icons-material';
|
||||
import { ButtonBase, Divider, Tooltip, useMediaQuery, useTheme } from '@mui/material';
|
||||
import clsx from 'clsx';
|
||||
import dayjs from 'dayjs';
|
||||
import { get } from 'lodash';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import toast from 'react-hot-toast';
|
||||
@ -67,8 +68,9 @@ const ArtboardController: React.FC<ReactZoomPanPinchRef> = ({ zoomIn, zoomOut, c
|
||||
|
||||
const slug = get(resume, 'slug');
|
||||
const username = get(resume, 'user.username');
|
||||
const updatedAt = get(resume, 'updatedAt');
|
||||
|
||||
const url = await mutateAsync({ username, slug });
|
||||
const url = await mutateAsync({ username, slug, lastUpdated: dayjs(updatedAt).unix().toString() });
|
||||
|
||||
download(url);
|
||||
};
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { PictureAsPdf, Schema } from '@mui/icons-material';
|
||||
import { List, ListItem, ListItemButton, ListItemText } from '@mui/material';
|
||||
import dayjs from 'dayjs';
|
||||
import get from 'lodash/get';
|
||||
import pick from 'lodash/pick';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
@ -45,8 +46,9 @@ const Export = () => {
|
||||
|
||||
const slug = get(resume, 'slug');
|
||||
const username = get(resume, 'user.username');
|
||||
const updatedAt = get(resume, 'updatedAt');
|
||||
|
||||
const url = await mutateAsync({ username, slug });
|
||||
const url = await mutateAsync({ username, slug, lastUpdated: dayjs(updatedAt).unix().toString() });
|
||||
|
||||
download(url);
|
||||
};
|
||||
|
||||
@ -2,6 +2,7 @@ import { Download, Downloading } from '@mui/icons-material';
|
||||
import { ButtonBase } from '@mui/material';
|
||||
import { Resume } from '@reactive-resume/schema';
|
||||
import clsx from 'clsx';
|
||||
import dayjs from 'dayjs';
|
||||
import download from 'downloadjs';
|
||||
import get from 'lodash/get';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
@ -96,7 +97,9 @@ const Preview: NextPage<Props> = ({ username, slug, resume: initialData }) => {
|
||||
|
||||
const handleDownload = async () => {
|
||||
try {
|
||||
const url = await mutateAsync({ username, slug });
|
||||
const updatedAt = get(resume, 'updatedAt');
|
||||
|
||||
const url = await mutateAsync({ username, slug, lastUpdated: dayjs(updatedAt).unix().toString() });
|
||||
|
||||
download(url);
|
||||
} catch {
|
||||
|
||||
@ -2,6 +2,7 @@ import { Download, Downloading } from '@mui/icons-material';
|
||||
import { ButtonBase } from '@mui/material';
|
||||
import { Resume } from '@reactive-resume/schema';
|
||||
import clsx from 'clsx';
|
||||
import dayjs from 'dayjs';
|
||||
import download from 'downloadjs';
|
||||
import get from 'lodash/get';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
@ -69,7 +70,7 @@ const Preview: NextPage<Props> = ({ shortId }) => {
|
||||
|
||||
const handleDownload = async () => {
|
||||
try {
|
||||
const url = await mutateAsync({ username: resume.user.username, slug: resume.slug });
|
||||
const url = await mutateAsync({ username: resume.user.username, slug: resume.slug, lastUpdated: dayjs(resume.updatedAt).unix().toString() });
|
||||
|
||||
download(url);
|
||||
} catch {
|
||||
|
||||
@ -3,7 +3,9 @@ import axios from './axios';
|
||||
export type PrintResumeAsPdfParams = {
|
||||
username: string;
|
||||
slug: string;
|
||||
lastUpdated: string;
|
||||
};
|
||||
|
||||
export const printResumeAsPdf = (printResumeAsPdfParams: PrintResumeAsPdfParams): Promise<string> =>
|
||||
axios.get(`/printer/${printResumeAsPdfParams.username}/${printResumeAsPdfParams.slug}`).then((res) => res.data);
|
||||
axios.get(`/printer/${printResumeAsPdfParams.username}/${printResumeAsPdfParams.slug}?lastUpdated=${printResumeAsPdfParams.lastUpdated}`)
|
||||
.then((res) => res.data);
|
||||
|
||||
@ -34,7 +34,7 @@ const store = configureStore({
|
||||
},
|
||||
});
|
||||
|
||||
sagaMiddleware.run(syncSaga);
|
||||
sagaMiddleware.run(() => syncSaga(store.dispatch));
|
||||
|
||||
export const persistor = persistStore(store);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import debounce from 'lodash/debounce';
|
||||
import { select, takeLatest } from 'redux-saga/effects';
|
||||
|
||||
import { updateResume } from '@/services/resume';
|
||||
import { RootState } from '@/store/index';
|
||||
import { AppDispatch, RootState } from '@/store/index';
|
||||
|
||||
import {
|
||||
addItem,
|
||||
@ -12,23 +12,24 @@ import {
|
||||
deleteSection,
|
||||
duplicateItem,
|
||||
editItem,
|
||||
setResume,
|
||||
setResumeState,
|
||||
} from '../resume/resumeSlice';
|
||||
|
||||
const DEBOUNCE_WAIT = 1000;
|
||||
|
||||
const debouncedSync = debounce((resume: Resume) => updateResume(resume), DEBOUNCE_WAIT);
|
||||
const debouncedSync = debounce((resume: Resume, dispatch: AppDispatch) => updateResume(resume).then((resume) => dispatch(setResume(resume))), DEBOUNCE_WAIT);
|
||||
|
||||
function* handleSync() {
|
||||
function* handleSync(dispatch: AppDispatch) {
|
||||
const resume: Resume = yield select((state: RootState) => state.resume.present);
|
||||
|
||||
debouncedSync(resume);
|
||||
debouncedSync(resume, dispatch);
|
||||
}
|
||||
|
||||
function* syncSaga() {
|
||||
function* syncSaga(dispatch: AppDispatch) {
|
||||
yield takeLatest(
|
||||
[setResumeState, addItem, editItem, duplicateItem, deleteItem, addSection, deleteSection],
|
||||
handleSync
|
||||
() => handleSync(dispatch)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user