fix: revalidating using swr

This commit is contained in:
sriram veeraghanta 2023-08-31 18:43:37 +05:30
parent 66bee2a094
commit 1cd1f6e8c9
3 changed files with 20 additions and 89 deletions

View File

@ -19,6 +19,7 @@
"nprogress": "^0.2.0", "nprogress": "^0.2.0",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"swr": "^2.2.2",
"typescript": "4.9.5", "typescript": "4.9.5",
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },

View File

@ -1,103 +1,33 @@
import { useEffect } from "react"; import useSWR from "swr";
import type { GetServerSideProps } from "next"; import type { GetServerSideProps } from "next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import Head from "next/head"; import Head from "next/head";
// types /// layouts
import { TIssueBoardKeys } from "types";
import ProjectLayout from "layouts/project-layout"; import ProjectLayout from "layouts/project-layout";
// components
import { ProjectDetailsView } from "components/views/project-details"; import { ProjectDetailsView } from "components/views/project-details";
// lib
import { useMobxStore } from "lib/mobx/store-provider";
const WorkspaceProjectPage = (props: any) => { const WorkspaceProjectPage = (props: any) => {
console.log("props", props);
const SITE_TITLE = props?.project_settings?.project_details?.name || "Plane | Deploy"; const SITE_TITLE = props?.project_settings?.project_details?.name || "Plane | Deploy";
const router = useRouter(); const router = useRouter();
const { workspace_slug, project_slug, states, labels, priorities } = router.query;
// const activeIssueId = store.issue.activePeekOverviewIssueId; const { project: projectStore, issue: issueStore } = useMobxStore();
const { workspace_slug, project_slug, board, states, labels, priorities } = router.query as { useSWR("REVALIDATE_ALL", () => {
workspace_slug: string; if (workspace_slug && project_slug) {
project_slug: string; projectStore.fetchProjectSettings(workspace_slug.toString(), project_slug.toString());
board: TIssueBoardKeys; const params = {
states: string[]; state: states || null,
labels: string[]; labels: labels || null,
priorities: string[]; priority: priorities || null,
}; };
issueStore.fetchPublicIssues(workspace_slug.toString(), project_slug.toString(), params);
// updating default board view when we are in the issues page }
// useEffect(() => { });
// if (workspace_slug && project_slug && store?.project?.workspaceProjectSettings) {
// const workspaceProjectSettingViews = store?.project?.workspaceProjectSettings?.views;
// const userAccessViews: TIssueBoardKeys[] = [];
// Object.keys(workspaceProjectSettingViews).filter((_key) => {
// if (_key === "list" && workspaceProjectSettingViews.list === true) userAccessViews.push(_key);
// if (_key === "kanban" && workspaceProjectSettingViews.kanban === true) userAccessViews.push(_key);
// if (_key === "calendar" && workspaceProjectSettingViews.calendar === true) userAccessViews.push(_key);
// if (_key === "spreadsheet" && workspaceProjectSettingViews.spreadsheet === true) userAccessViews.push(_key);
// if (_key === "gantt" && workspaceProjectSettingViews.gantt === true) userAccessViews.push(_key);
// });
// let url = `/${workspace_slug}/${project_slug}`;
// let _board = board;
// if (userAccessViews && userAccessViews.length > 0) {
// if (!board) {
// store.issue.setCurrentIssueBoardView(userAccessViews[0]);
// _board = userAccessViews[0];
// } else {
// if (userAccessViews.includes(board)) {
// if (store.issue.currentIssueBoardView === null) store.issue.setCurrentIssueBoardView(board);
// else {
// if (board === store.issue.currentIssueBoardView) {
// _board = board;
// } else {
// _board = board;
// store.issue.setCurrentIssueBoardView(board);
// }
// }
// } else {
// store.issue.setCurrentIssueBoardView(userAccessViews[0]);
// _board = userAccessViews[0];
// }
// }
// }
// _board = _board || "list";
// url = `${url}?board=${_board}`;
// if (states) url = `${url}&states=${states}`;
// if (labels) url = `${url}&labels=${labels}`;
// if (priorities) url = `${url}&priorities=${priorities}`;
// url = decodeURIComponent(url);
// router.replace(url);
// }
// }, [
// workspace_slug,
// project_slug,
// board,
// router,
// store?.issue,
// store?.project?.workspaceProjectSettings,
// states,
// labels,
// priorities,
// ]);
// useEffect(() => {
// if (!workspace_slug || !project_slug) return;
// const params = {
// state: states || null,
// labels: labels || null,
// priority: priorities || null,
// };
// store?.project?.getProjectSettingsAsync(workspace_slug, project_slug);
// store?.issue?.getIssuesAsync(workspace_slug, project_slug, params);
// }, [workspace_slug, project_slug, store?.project, store?.issue, states, labels, priorities]);
return ( return (
<ProjectLayout> <ProjectLayout>

View File

@ -7551,7 +7551,7 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
swr@^2.1.3: swr@^2.1.3, swr@^2.2.2:
version "2.2.2" version "2.2.2"
resolved "https://registry.yarnpkg.com/swr/-/swr-2.2.2.tgz#abcb1f9c97e10527789884169d58b878472d4c98" resolved "https://registry.yarnpkg.com/swr/-/swr-2.2.2.tgz#abcb1f9c97e10527789884169d58b878472d4c98"
integrity sha512-CbR41AoMD4TQBQw9ic3GTXspgfM9Y8Mdhb5Ob4uIKXhWqnRLItwA5fpGvB7SmSw3+zEjb0PdhiEumtUvYoQ+bQ== integrity sha512-CbR41AoMD4TQBQw9ic3GTXspgfM9Y8Mdhb5Ob4uIKXhWqnRLItwA5fpGvB7SmSw3+zEjb0PdhiEumtUvYoQ+bQ==