@osdk/create-app 0.17.0-main-20240529132607 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -1
- package/build/browser/index.js +16 -14
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +16 -15
- package/build/cjs/index.cjs.map +1 -1
- package/build/esm/index.js +16 -14
- package/build/esm/index.js.map +1 -1
- package/build/esm/run.d.ts.map +1 -1
- package/build/esm/templates.d.ts.map +1 -1
- package/package.json +19 -10
- package/templates/template-next-static-export/.eslintrc.json +0 -4
- package/templates/template-next-static-export/README.md.hbs +0 -35
- package/templates/template-next-static-export/_gitignore +0 -36
- package/templates/template-next-static-export/next.config.js.hbs +0 -17
- package/templates/template-next-static-export/package.json.hbs +0 -25
- package/templates/template-next-static-export/public/next.svg +0 -20
- package/templates/template-next-static-export/public/palantir.svg +0 -3
- package/templates/template-next-static-export/src/app/auth/callback/page.tsx +0 -25
- package/templates/template-next-static-export/src/app/globals.css +0 -81
- package/templates/template-next-static-export/src/app/icon.svg +0 -20
- package/templates/template-next-static-export/src/app/layout.module.css +0 -11
- package/templates/template-next-static-export/src/app/layout.tsx +0 -51
- package/templates/template-next-static-export/src/app/login/page.tsx +0 -43
- package/templates/template-next-static-export/src/app/page.module.css +0 -7
- package/templates/template-next-static-export/src/app/page.tsx.hbs +0 -53
- package/templates/template-next-static-export/src/lib/client.ts.hbs +0 -31
- package/templates/template-next-static-export/src/lib/useAuthenticated.ts +0 -25
- package/templates/template-next-static-export/tsconfig.json +0 -27
- package/templates/template-react/.eslintrc.cjs +0 -18
- package/templates/template-react/README.md.hbs +0 -35
- package/templates/template-react/_gitignore +0 -24
- package/templates/template-react/index.html +0 -15
- package/templates/template-react/package.json.hbs +0 -30
- package/templates/template-react/public/palantir.svg +0 -3
- package/templates/template-react/public/react.svg +0 -1
- package/templates/template-react/src/AuthCallback.tsx +0 -24
- package/templates/template-react/src/AuthenticatedRoute.tsx +0 -33
- package/templates/template-react/src/Home.module.css +0 -7
- package/templates/template-react/src/Home.tsx.hbs +0 -47
- package/templates/template-react/src/Layout.module.css +0 -10
- package/templates/template-react/src/Layout.tsx +0 -29
- package/templates/template-react/src/Login.tsx +0 -40
- package/templates/template-react/src/client.ts.hbs +0 -31
- package/templates/template-react/src/index.css +0 -81
- package/templates/template-react/src/main.tsx +0 -33
- package/templates/template-react/src/vite-env.d.ts +0 -1
- package/templates/template-react/tsconfig.json +0 -25
- package/templates/template-react/tsconfig.node.json +0 -10
- package/templates/template-react/vite.config.ts.hbs +0 -19
- package/templates/template-tutorial-todo-app/.eslintrc.cjs +0 -18
- package/templates/template-tutorial-todo-app/README.md.hbs +0 -33
- package/templates/template-tutorial-todo-app/index.html +0 -15
- package/templates/template-tutorial-todo-app/package.json.hbs +0 -31
- package/templates/template-tutorial-todo-app/public/todo-app.svg +0 -4
- package/templates/template-tutorial-todo-app/src/AuthCallback.tsx +0 -24
- package/templates/template-tutorial-todo-app/src/AuthenticatedRoute.tsx +0 -33
- package/templates/template-tutorial-todo-app/src/CreateProjectButton.tsx +0 -33
- package/templates/template-tutorial-todo-app/src/CreateProjectDialog.tsx +0 -56
- package/templates/template-tutorial-todo-app/src/CreateTaskButton.tsx +0 -35
- package/templates/template-tutorial-todo-app/src/CreateTaskDialog.tsx +0 -52
- package/templates/template-tutorial-todo-app/src/DeleteProjectButton.tsx +0 -34
- package/templates/template-tutorial-todo-app/src/DeleteProjectDialog.tsx +0 -46
- package/templates/template-tutorial-todo-app/src/Dialog.module.css +0 -5
- package/templates/template-tutorial-todo-app/src/Dialog.tsx +0 -19
- package/templates/template-tutorial-todo-app/src/Home.module.css +0 -35
- package/templates/template-tutorial-todo-app/src/Home.tsx +0 -62
- package/templates/template-tutorial-todo-app/src/Layout.module.css +0 -16
- package/templates/template-tutorial-todo-app/src/Layout.tsx +0 -21
- package/templates/template-tutorial-todo-app/src/Login.module.css +0 -5
- package/templates/template-tutorial-todo-app/src/Login.tsx +0 -42
- package/templates/template-tutorial-todo-app/src/ProjectSelect.tsx +0 -40
- package/templates/template-tutorial-todo-app/src/TaskList.module.css +0 -6
- package/templates/template-tutorial-todo-app/src/TaskList.tsx +0 -38
- package/templates/template-tutorial-todo-app/src/TaskListItem.module.css +0 -3
- package/templates/template-tutorial-todo-app/src/TaskListItem.tsx +0 -37
- package/templates/template-tutorial-todo-app/src/client.ts.hbs +0 -31
- package/templates/template-tutorial-todo-app/src/index.css +0 -80
- package/templates/template-tutorial-todo-app/src/main.tsx +0 -33
- package/templates/template-tutorial-todo-app/src/mocks.ts +0 -137
- package/templates/template-tutorial-todo-app/src/useProjectTasks.ts +0 -55
- package/templates/template-tutorial-todo-app/src/useProjects.ts +0 -43
- package/templates/template-tutorial-todo-app/src/vite-env.d.ts +0 -1
- package/templates/template-tutorial-todo-app/tsconfig.json +0 -25
- package/templates/template-tutorial-todo-app/tsconfig.node.json +0 -10
- package/templates/template-tutorial-todo-app/vite.config.ts.hbs +0 -19
- package/templates/template-vue/.vscode/extensions.json +0 -3
- package/templates/template-vue/README.md.hbs +0 -35
- package/templates/template-vue/_gitignore +0 -24
- package/templates/template-vue/index.html +0 -15
- package/templates/template-vue/package.json.hbs +0 -22
- package/templates/template-vue/public/palantir.svg +0 -3
- package/templates/template-vue/public/vue.svg +0 -1
- package/templates/template-vue/src/AuthCallback.vue +0 -22
- package/templates/template-vue/src/Home.vue.hbs +0 -38
- package/templates/template-vue/src/Layout.vue +0 -26
- package/templates/template-vue/src/Login.vue +0 -36
- package/templates/template-vue/src/client.ts.hbs +0 -31
- package/templates/template-vue/src/main.ts +0 -35
- package/templates/template-vue/src/style.css +0 -81
- package/templates/template-vue/src/vite-env.d.ts +0 -1
- package/templates/template-vue/tsconfig.json +0 -25
- package/templates/template-vue/tsconfig.node.json +0 -10
- package/templates/template-vue/vite.config.ts.hbs +0 -24
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from "react";
|
|
2
|
-
import CreateProjectButton from "./CreateProjectButton";
|
|
3
|
-
import CreateTaskButton from "./CreateTaskButton";
|
|
4
|
-
import DeleteProjectButton from "./DeleteProjectButton";
|
|
5
|
-
import css from "./Home.module.css";
|
|
6
|
-
import Layout from "./Layout";
|
|
7
|
-
import { MockProject } from "./mocks";
|
|
8
|
-
import ProjectSelect from "./ProjectSelect";
|
|
9
|
-
import TaskList from "./TaskList";
|
|
10
|
-
import useProjects from "./useProjects";
|
|
11
|
-
|
|
12
|
-
function Home() {
|
|
13
|
-
const [projectId, setProjectId] = useState<string | undefined>(undefined);
|
|
14
|
-
const { projects } = useProjects();
|
|
15
|
-
const project = projects?.find((p) => p.id === projectId);
|
|
16
|
-
|
|
17
|
-
const handleSelectProject = useCallback(
|
|
18
|
-
(p: MockProject) => setProjectId(p.id),
|
|
19
|
-
[],
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
if (project == null && projects != null && projects.length > 0) {
|
|
24
|
-
setProjectId(projects[0].id);
|
|
25
|
-
}
|
|
26
|
-
}, [project, projects]);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Layout>
|
|
30
|
-
<div className={css.tutorialBannerWrapper}>
|
|
31
|
-
<div className={css.tutorialBanner}>
|
|
32
|
-
<p className={css.tutorialBannerTitle}>
|
|
33
|
-
💡 Welcome to this tutorial!
|
|
34
|
-
</p>
|
|
35
|
-
<p>
|
|
36
|
-
The Todo App below has been implemented with fake in memory data.
|
|
37
|
-
Can you solve how to switch it to use the Ontology SDK instead?
|
|
38
|
-
</p>
|
|
39
|
-
</div>
|
|
40
|
-
</div>
|
|
41
|
-
<div className={css.projectSelect}>
|
|
42
|
-
<span>Project:</span>
|
|
43
|
-
<ProjectSelect
|
|
44
|
-
project={project}
|
|
45
|
-
projects={projects ?? []}
|
|
46
|
-
onSelectProject={handleSelectProject}
|
|
47
|
-
/>
|
|
48
|
-
<CreateProjectButton onProjectCreated={setProjectId} />
|
|
49
|
-
{project != null && <DeleteProjectButton project={project} />}
|
|
50
|
-
</div>
|
|
51
|
-
{project != null && (
|
|
52
|
-
<div className={css.projectCard} key={project.id}>
|
|
53
|
-
<h1 className={css.projectTitle}>{project.name}</h1>
|
|
54
|
-
<TaskList project={project} />
|
|
55
|
-
<CreateTaskButton project={project} />
|
|
56
|
-
</div>
|
|
57
|
-
)}
|
|
58
|
-
</Layout>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default Home;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import todoAppLogo from "/todo-app.svg";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import css from "./Layout.module.css";
|
|
4
|
-
|
|
5
|
-
interface LayoutProps {
|
|
6
|
-
children?: React.ReactNode;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function Layout({ children }: LayoutProps) {
|
|
10
|
-
return (
|
|
11
|
-
<>
|
|
12
|
-
<div className={css.header}>
|
|
13
|
-
<img src={todoAppLogo} className={css.logo} alt="Todo App logo" />
|
|
14
|
-
<div className={css.title}>Ontology SDK Tutorial - Todo App</div>
|
|
15
|
-
</div>
|
|
16
|
-
{children}
|
|
17
|
-
</>
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default Layout;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from "react";
|
|
2
|
-
import { Navigate } from "react-router-dom";
|
|
3
|
-
import client from "./client";
|
|
4
|
-
import Layout from "./Layout";
|
|
5
|
-
import css from "./Login.module.css";
|
|
6
|
-
|
|
7
|
-
function Login() {
|
|
8
|
-
const [isLoggingIn, setIsLoggingIn] = useState(false);
|
|
9
|
-
const [error, setError] = useState<string | undefined>(undefined);
|
|
10
|
-
const token = client.auth.token;
|
|
11
|
-
|
|
12
|
-
const handleLogin = useCallback(async () => {
|
|
13
|
-
setIsLoggingIn(true);
|
|
14
|
-
try {
|
|
15
|
-
// Initiate the OAuth flow, which will redirect the user to log into Foundry
|
|
16
|
-
// Once the login has completed, the user will be redirected back to the route defined via the
|
|
17
|
-
// FOUNDRY_REDIRECT_URL variable in .env.development
|
|
18
|
-
await client.auth.signIn();
|
|
19
|
-
} catch (e: unknown) {
|
|
20
|
-
console.error(e);
|
|
21
|
-
setError((e as Error).message ?? e);
|
|
22
|
-
}
|
|
23
|
-
}, []);
|
|
24
|
-
|
|
25
|
-
// If the token exists but a user tries to load /login, redirect to the home page instead
|
|
26
|
-
if (token != null) {
|
|
27
|
-
return <Navigate to="/" replace={true} />;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<Layout>
|
|
32
|
-
<div className={css.loginButton}>
|
|
33
|
-
<button onClick={handleLogin}>
|
|
34
|
-
{isLoggingIn ? "Logging in…" : "Log in "}
|
|
35
|
-
</button>
|
|
36
|
-
</div>
|
|
37
|
-
{error && <div>Unable to log in: {error}</div>}
|
|
38
|
-
</Layout>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default Login;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useCallback } from "react";
|
|
2
|
-
import { MockProject } from "./mocks";
|
|
3
|
-
|
|
4
|
-
interface ProjectSelectProps {
|
|
5
|
-
project: MockProject | undefined;
|
|
6
|
-
projects: MockProject[];
|
|
7
|
-
onSelectProject: (project: MockProject) => void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function ProjectSelect({
|
|
11
|
-
project,
|
|
12
|
-
projects,
|
|
13
|
-
onSelectProject,
|
|
14
|
-
}: ProjectSelectProps) {
|
|
15
|
-
const handleSelect = useCallback(
|
|
16
|
-
(e: ChangeEvent<HTMLSelectElement>) => {
|
|
17
|
-
const nextProject = projects.find((p) => `${p.id}` === e.target.value);
|
|
18
|
-
if (nextProject != null) {
|
|
19
|
-
onSelectProject(nextProject);
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
[projects, onSelectProject],
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<select value={project?.id} onChange={handleSelect}>
|
|
27
|
-
<option hidden disabled selected>
|
|
28
|
-
-- select a project --
|
|
29
|
-
</option>
|
|
30
|
-
|
|
31
|
-
{projects.map((p) => (
|
|
32
|
-
<option key={p.id} value={p.id}>
|
|
33
|
-
{p.name}
|
|
34
|
-
</option>
|
|
35
|
-
))}
|
|
36
|
-
</select>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default ProjectSelect;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { MockProject } from "./mocks";
|
|
2
|
-
import css from "./TaskList.module.css";
|
|
3
|
-
import TaskListItem from "./TaskListItem";
|
|
4
|
-
import { useProjectTasks } from "./useProjectTasks";
|
|
5
|
-
|
|
6
|
-
interface TaskListProps {
|
|
7
|
-
project: MockProject;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function TaskList({ project }: TaskListProps) {
|
|
11
|
-
const {
|
|
12
|
-
tasks,
|
|
13
|
-
isLoading: isLoadingTasks,
|
|
14
|
-
isError: isErrorTasks,
|
|
15
|
-
deleteTask,
|
|
16
|
-
} = useProjectTasks(project);
|
|
17
|
-
|
|
18
|
-
if (isErrorTasks) {
|
|
19
|
-
return <div className={css.taskList}>Error loading tasks!</div>;
|
|
20
|
-
} else if (isLoadingTasks) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const data = tasks ?? [];
|
|
25
|
-
if (data.length === 0) {
|
|
26
|
-
return <div className={css.taskList}>No tasks found</div>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<ul className={css.taskList}>
|
|
31
|
-
{data.map((task) => (
|
|
32
|
-
<TaskListItem key={task.id} task={task} deleteTask={deleteTask} />
|
|
33
|
-
))}
|
|
34
|
-
</ul>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default TaskList;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from "react";
|
|
2
|
-
import { MockTask } from "./mocks";
|
|
3
|
-
import css from "./TaskListItem.module.css";
|
|
4
|
-
|
|
5
|
-
interface TaskListItemProps {
|
|
6
|
-
task: MockTask;
|
|
7
|
-
deleteTask: (task: MockTask) => Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function TaskListItem({ task, deleteTask }: TaskListItemProps) {
|
|
11
|
-
const [isDeleting, setIsDeleting] = useState(false);
|
|
12
|
-
const handleClick = useCallback(async () => {
|
|
13
|
-
setIsDeleting(true);
|
|
14
|
-
try {
|
|
15
|
-
await deleteTask(task);
|
|
16
|
-
} finally {
|
|
17
|
-
setIsDeleting(false);
|
|
18
|
-
}
|
|
19
|
-
}, [deleteTask, task]);
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<li>
|
|
23
|
-
<input
|
|
24
|
-
id={`${task.id}`}
|
|
25
|
-
type="checkbox"
|
|
26
|
-
onClick={handleClick}
|
|
27
|
-
checked={isDeleting}
|
|
28
|
-
disabled={isDeleting}
|
|
29
|
-
/>
|
|
30
|
-
<label className={css.label} htmlFor={`${task.id}`}>
|
|
31
|
-
{task.title}
|
|
32
|
-
</label>
|
|
33
|
-
</li>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default TaskListItem;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FoundryClient, PublicClientAuth } from "{{osdkPackage}}";
|
|
2
|
-
|
|
3
|
-
const url = import.meta.env.VITE_FOUNDRY_API_URL;
|
|
4
|
-
const clientId = import.meta.env.VITE_FOUNDRY_CLIENT_ID;
|
|
5
|
-
const redirectUrl = import.meta.env.VITE_FOUNDRY_REDIRECT_URL;
|
|
6
|
-
checkEnv(url, "VITE_FOUNDRY_API_URL");
|
|
7
|
-
checkEnv(clientId, "VITE_FOUNDRY_CLIENT_ID");
|
|
8
|
-
checkEnv(redirectUrl, "VITE_FOUNDRY_REDIRECT_URL");
|
|
9
|
-
|
|
10
|
-
function checkEnv(
|
|
11
|
-
value: string | undefined,
|
|
12
|
-
name: string,
|
|
13
|
-
): asserts value is string {
|
|
14
|
-
if (value == null) {
|
|
15
|
-
throw new Error(`Missing environment variable: ${name}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Initialize the client to interact with the Ontology SDK
|
|
21
|
-
*/
|
|
22
|
-
const client = new FoundryClient({
|
|
23
|
-
url,
|
|
24
|
-
auth: new PublicClientAuth({
|
|
25
|
-
clientId,
|
|
26
|
-
url,
|
|
27
|
-
redirectUrl,
|
|
28
|
-
}),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export default client;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
:root {
|
|
2
|
-
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
-
line-height: 1.5;
|
|
4
|
-
font-weight: 400;
|
|
5
|
-
|
|
6
|
-
color-scheme: light dark;
|
|
7
|
-
color: rgba(255, 255, 255, 0.87);
|
|
8
|
-
background-color: #242424;
|
|
9
|
-
|
|
10
|
-
font-synthesis: none;
|
|
11
|
-
text-rendering: optimizeLegibility;
|
|
12
|
-
-webkit-font-smoothing: antialiased;
|
|
13
|
-
-moz-osx-font-smoothing: grayscale;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
#root-container {
|
|
17
|
-
display: flex;
|
|
18
|
-
flex: 1;
|
|
19
|
-
align-items: center;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
#root {
|
|
23
|
-
max-width: 1280px;
|
|
24
|
-
margin: 2rem auto;
|
|
25
|
-
padding: 2rem;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
a {
|
|
29
|
-
font-weight: 500;
|
|
30
|
-
color: #646cff;
|
|
31
|
-
text-decoration: inherit;
|
|
32
|
-
}
|
|
33
|
-
a:hover {
|
|
34
|
-
color: #535bf2;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
body {
|
|
38
|
-
margin: 0;
|
|
39
|
-
display: flex;
|
|
40
|
-
flex-direction: column;
|
|
41
|
-
min-width: 320px;
|
|
42
|
-
min-height: 100vh;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
h1 {
|
|
46
|
-
font-size: 3.2em;
|
|
47
|
-
line-height: 1.1;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
button {
|
|
51
|
-
border-radius: 8px;
|
|
52
|
-
border: 1px solid transparent;
|
|
53
|
-
padding: 0.6em 1.2em;
|
|
54
|
-
font-size: 1em;
|
|
55
|
-
font-weight: 500;
|
|
56
|
-
font-family: inherit;
|
|
57
|
-
background-color: #1a1a1a;
|
|
58
|
-
cursor: pointer;
|
|
59
|
-
transition: border-color 0.25s;
|
|
60
|
-
}
|
|
61
|
-
button:hover {
|
|
62
|
-
border-color: #646cff;
|
|
63
|
-
}
|
|
64
|
-
button:focus,
|
|
65
|
-
button:focus-visible {
|
|
66
|
-
outline: 4px auto -webkit-focus-ring-color;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
@media (prefers-color-scheme: light) {
|
|
70
|
-
:root {
|
|
71
|
-
color: #213547;
|
|
72
|
-
background-color: #ffffff;
|
|
73
|
-
}
|
|
74
|
-
a:hover {
|
|
75
|
-
color: #747bff;
|
|
76
|
-
}
|
|
77
|
-
button {
|
|
78
|
-
background-color: #f9f9f9;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import ReactDOM from "react-dom/client";
|
|
2
|
-
import { createBrowserRouter, RouterProvider } from "react-router-dom";
|
|
3
|
-
import AuthCallback from "./AuthCallback";
|
|
4
|
-
import AuthenticatedRoute from "./AuthenticatedRoute";
|
|
5
|
-
import Home from "./Home";
|
|
6
|
-
import Login from "./Login";
|
|
7
|
-
import "./index.css";
|
|
8
|
-
|
|
9
|
-
const router = createBrowserRouter([
|
|
10
|
-
{
|
|
11
|
-
path: "/",
|
|
12
|
-
element: <AuthenticatedRoute />,
|
|
13
|
-
children: [
|
|
14
|
-
{
|
|
15
|
-
path: "/",
|
|
16
|
-
element: <Home />,
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
path: "/login",
|
|
22
|
-
element: <Login />,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
// This is the route defined in your application's redirect URL
|
|
26
|
-
path: "/auth/callback",
|
|
27
|
-
element: <AuthCallback />,
|
|
28
|
-
},
|
|
29
|
-
]);
|
|
30
|
-
|
|
31
|
-
ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
32
|
-
<RouterProvider router={router} />,
|
|
33
|
-
);
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
export interface MockProject {
|
|
2
|
-
__apiName: string;
|
|
3
|
-
__primaryKey: string;
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
tasks: MockTask[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface MockTask {
|
|
10
|
-
__apiName: string;
|
|
11
|
-
__primaryKey: string;
|
|
12
|
-
id: string;
|
|
13
|
-
title: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const projects: MockProject[] = [
|
|
17
|
-
{
|
|
18
|
-
__apiName: "MockProject",
|
|
19
|
-
__primaryKey: "1",
|
|
20
|
-
id: "1",
|
|
21
|
-
name: "Fake Project",
|
|
22
|
-
tasks: [
|
|
23
|
-
{
|
|
24
|
-
__apiName: "MockTask",
|
|
25
|
-
__primaryKey: "1",
|
|
26
|
-
id: "1",
|
|
27
|
-
title: "Try to",
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
__apiName: "MockTask",
|
|
31
|
-
__primaryKey: "2",
|
|
32
|
-
id: "2",
|
|
33
|
-
title: "Implement this",
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
__apiName: "MockTask",
|
|
37
|
-
__primaryKey: "3",
|
|
38
|
-
id: "3",
|
|
39
|
-
title: "With the Ontology SDK!",
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
__apiName: "MockProject",
|
|
45
|
-
__primaryKey: "2",
|
|
46
|
-
id: "2",
|
|
47
|
-
name: "Yet Another Fake Project",
|
|
48
|
-
tasks: [
|
|
49
|
-
{
|
|
50
|
-
__apiName: "MockTask",
|
|
51
|
-
__primaryKey: "4",
|
|
52
|
-
id: "4",
|
|
53
|
-
title: "More tasks here",
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
async function delay(): Promise<void> {
|
|
60
|
-
return new Promise((resolve) =>
|
|
61
|
-
setTimeout(() => resolve(), 500 + Math.random() * 1000)
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Good enough random id for mocks
|
|
66
|
-
function randomId(): string {
|
|
67
|
-
return `${Math.floor(Math.random() * 2 ** 31)}`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function getProjects(): Promise<MockProject[]> {
|
|
71
|
-
await delay();
|
|
72
|
-
const result = [...projects];
|
|
73
|
-
result.sort((p1, p2) => p1.name.localeCompare(p2.name));
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function createProject({
|
|
78
|
-
name,
|
|
79
|
-
}: {
|
|
80
|
-
name: string;
|
|
81
|
-
}): Promise<MockTask["__primaryKey"]> {
|
|
82
|
-
await delay();
|
|
83
|
-
const id = randomId();
|
|
84
|
-
projects.push({
|
|
85
|
-
__apiName: "MockProject",
|
|
86
|
-
__primaryKey: id,
|
|
87
|
-
id,
|
|
88
|
-
name,
|
|
89
|
-
tasks: [],
|
|
90
|
-
});
|
|
91
|
-
return id;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function deleteProject(id: string): Promise<void> {
|
|
95
|
-
await delay();
|
|
96
|
-
const idx = projects.findIndex((p) => p.id === id);
|
|
97
|
-
if (idx !== -1) {
|
|
98
|
-
projects.splice(idx, 1);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function createTask({
|
|
103
|
-
title,
|
|
104
|
-
projectId,
|
|
105
|
-
}: {
|
|
106
|
-
title: string;
|
|
107
|
-
projectId: string;
|
|
108
|
-
}): Promise<MockTask["__primaryKey"]> {
|
|
109
|
-
await delay();
|
|
110
|
-
const project = projects.find((p) => p.id === projectId);
|
|
111
|
-
if (project == null) {
|
|
112
|
-
throw new Error(`Project ${projectId} not found!`);
|
|
113
|
-
}
|
|
114
|
-
const id = randomId();
|
|
115
|
-
project.tasks.unshift({ __apiName: "MockTask", __primaryKey: id, id, title });
|
|
116
|
-
return id;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function deleteTask(id: string): Promise<void> {
|
|
120
|
-
await delay();
|
|
121
|
-
for (const project of projects) {
|
|
122
|
-
const idx = project.tasks.findIndex((t) => t.id === id);
|
|
123
|
-
if (idx !== -1) {
|
|
124
|
-
project.tasks.splice(idx, 1);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const Mocks = {
|
|
130
|
-
getProjects,
|
|
131
|
-
createProject,
|
|
132
|
-
deleteProject,
|
|
133
|
-
createTask,
|
|
134
|
-
deleteTask,
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export default Mocks;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import useSWR from "swr";
|
|
3
|
-
import Mocks, { MockProject, MockTask } from "./mocks";
|
|
4
|
-
|
|
5
|
-
export function useProjectTasks(project: MockProject | undefined) {
|
|
6
|
-
const { data, isLoading, isValidating, error, mutate } = useSWR<MockTask[]>(
|
|
7
|
-
project != null ? `projects/${project.id}/tasks` : null,
|
|
8
|
-
// Try to implement this with the Ontology SDK!
|
|
9
|
-
async () => {
|
|
10
|
-
if (project == null) {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
return project.tasks;
|
|
14
|
-
},
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const createTask: (
|
|
18
|
-
title: string,
|
|
19
|
-
) => Promise<MockTask["__primaryKey"] | undefined> = useCallback(
|
|
20
|
-
async (title) => {
|
|
21
|
-
if (project == null) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
// Try to implement this with the Ontology SDK!
|
|
25
|
-
const id = await Mocks.createTask({
|
|
26
|
-
title,
|
|
27
|
-
projectId: project.__primaryKey,
|
|
28
|
-
});
|
|
29
|
-
await mutate();
|
|
30
|
-
return id;
|
|
31
|
-
},
|
|
32
|
-
[project, mutate],
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const deleteTask: (task: MockTask) => Promise<void> = useCallback(
|
|
36
|
-
async (task) => {
|
|
37
|
-
if (project == null) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
// Try to implement this with the Ontology SDK!
|
|
41
|
-
await Mocks.deleteTask(task.__primaryKey);
|
|
42
|
-
await mutate();
|
|
43
|
-
},
|
|
44
|
-
[project, mutate],
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
tasks: data,
|
|
49
|
-
isLoading,
|
|
50
|
-
isValidating,
|
|
51
|
-
isError: error,
|
|
52
|
-
createTask,
|
|
53
|
-
deleteTask,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import useSWR from "swr";
|
|
3
|
-
import Mocks, { MockProject } from "./mocks";
|
|
4
|
-
|
|
5
|
-
function useProjects() {
|
|
6
|
-
const { data, isLoading, isValidating, error, mutate } = useSWR<
|
|
7
|
-
MockProject[]
|
|
8
|
-
>("projects", async () => {
|
|
9
|
-
// Try to implement this with the Ontology SDK!
|
|
10
|
-
return Mocks.getProjects();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const createProject: (name: string) => Promise<MockProject["__primaryKey"]> =
|
|
14
|
-
useCallback(
|
|
15
|
-
async (name) => {
|
|
16
|
-
// Try to implement this with the Ontology SDK!
|
|
17
|
-
const id = await Mocks.createProject({ name });
|
|
18
|
-
await mutate();
|
|
19
|
-
return id;
|
|
20
|
-
},
|
|
21
|
-
[mutate],
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const deleteProject: (project: MockProject) => Promise<void> = useCallback(
|
|
25
|
-
async (project) => {
|
|
26
|
-
// Try to implement this with the Ontology SDK!
|
|
27
|
-
await Mocks.deleteProject(project.__primaryKey);
|
|
28
|
-
await mutate();
|
|
29
|
-
},
|
|
30
|
-
[mutate],
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
projects: data,
|
|
35
|
-
isLoading,
|
|
36
|
-
isValidating,
|
|
37
|
-
isError: error,
|
|
38
|
-
createProject,
|
|
39
|
-
deleteProject,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default useProjects;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
|
|
9
|
-
/* Bundler mode */
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
"jsx": "react-jsx",
|
|
16
|
-
|
|
17
|
-
/* Linting */
|
|
18
|
-
"strict": true,
|
|
19
|
-
"noUnusedLocals": true,
|
|
20
|
-
"noUnusedParameters": true,
|
|
21
|
-
"noFallthroughCasesInSwitch": true
|
|
22
|
-
},
|
|
23
|
-
"include": ["src"],
|
|
24
|
-
"references": [{ "path": "./tsconfig.node.json" }]
|
|
25
|
-
}
|