Skip to content

Commit

Permalink
Child notes as project tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Nadler committed Mar 30, 2024
1 parent 5768dad commit 76782c6
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Project Journal
## Development Tasks / TODO
### v0.2.0
### MVP
- [x] Allow the user to modify the System Prompt
- [ ] Allow the user to select the OpenAI language model
- [ ] Allow the user to provide examples of output style
- [x] Allow the user to provide examples of output style
- [x] Generate all project summaries and compile into a top-level summary
- [x] Constrain summary to a specific date range
- [x] Integrate a Gantt chart overview
- [ ] Add tasks to the Gantt chart
- [x] Add tasks to the Gantt chart
- [ ] View a Gantt chart for a single project
### Future
- [ ] Support task and project dependencies in the Gantt chart
- [ ] Ingest and sync with notes on the file system (eg. Obsidian vault)
- [ ] Show summary streaming results from LLM
- [ ] Export notes as text files
- [ ] Allow the user to select the OpenAI language model

# Tauri + React + Typescript

Expand Down
100 changes: 99 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,105 @@ fn migrations() -> Vec<Migration> {
kind: MigrationKind::Up,
};

return vec![migration, m2, m3, m4, m5, m6];
let m7 = Migration {
version: 7,
description: "dont_cascade_delete",
sql: "create table status_dg_tmp
(
id integer not null
constraint status_pk
primary key autoincrement,
project_id integer
constraint status_projects_id_fk
references projects,
progress integer,
start_date text not null,
end_date text not null,
date_created text not null
);
insert into status_dg_tmp(id, project_id, progress, start_date, end_date, date_created)
select id, project_id, progress, start_date, end_date, date_created
from status;
drop table status;
alter table status_dg_tmp
rename to status;
create table entries_dg_tmp
(
id integer not null
constraint entries_pk
primary key,
date_created TEXT not null,
content text,
project_id integer not null
constraint entries_projects_id_fk
references projects,
date_updated TEXT
);
insert into entries_dg_tmp(id, date_created, content, project_id, date_updated)
select id, date_created, content, project_id, date_updated
from entries;
drop table entries;
alter table entries_dg_tmp
rename to entries;
",
kind: MigrationKind::Up,
};

let m8 = Migration {
version: 8,
description: "add_project_parent",
// https://github.com/launchbadge/sqlx/issues/2085#issuecomment-1499859906
sql: "-- remove the original TRANSACTION
COMMIT TRANSACTION;
-- tweak config
PRAGMA foreign_keys=OFF;
-- start your own TRANSACTION
BEGIN TRANSACTION;
create table projects_dg_tmp
(
id integer not null
constraint projects_pk
primary key autoincrement,
name text not null,
parent integer
constraint projects_projects_id_fk
references projects
);
insert into projects_dg_tmp(id, name)
select id, name
from projects;
drop table projects;
alter table projects_dg_tmp
rename to projects;
-- check foreign key constraint still upholding.
PRAGMA foreign_key_check;
-- commit your own TRANSACTION
COMMIT TRANSACTION;
-- rollback all config you setup before.
PRAGMA foreign_keys=ON;
-- start a new TRANSACTION to let migrator commit it.
BEGIN TRANSACTION;",
kind: MigrationKind::Up,
};

return vec![migration, m2, m3, m4, m5, m6, m7, m8];
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"productName": "Project Journal",
"version": "0.1.3",
"version": "0.2.0",
"identifier": "io.tortoise.project-journal",
"build": {
"beforeDevCommand": "npm run dev",
Expand Down
76 changes: 65 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
updateStatus,
deleteStatus,
getEntriesOverRange,
setProjectParent,
} from "./db";
import { PencilSquareIcon } from "@heroicons/react/24/solid";
import {
Expand Down Expand Up @@ -79,7 +80,7 @@ const useProjects = create<IProjectState>((set) => ({
set({ activeProject }),
}));

// const EXAMPLE_TASKS = [
// const EXAMPLE_TASKS: Task[] = [
// {
// start: dayjs("2024-01-01").toDate(),
// end: dayjs("2024-01-30").toDate(),
Expand Down Expand Up @@ -183,9 +184,11 @@ const GanttChart: React.FC = () => {
end: dayjs(getProjectStatus(p.id)?.end_date).toDate(),
name: p.name,
id: p.id.toString(),
type: "project",
type: p.parent ? "task" : "project",
progress: getProjectStatus(p.id)?.progress ?? 0,
project: p.parent?.toString(),
}))}
// tasks={EXAMPLE_TASKS}
/>
)
);
Expand All @@ -205,8 +208,7 @@ const Entry: React.FC<{ entry: IEntry; updateEntries: () => void }> = ({
<span className="flex justify-between pb-1 text-xs font-light">
<span className="flex gap-1">
<span className="text-indigo-400">
Created:{" "}
{dayjs(entry.date_created).format("YYYY-MM-DD h:mm a")}
Created: {dayjs(entry.date_created).format("YYYY-MM-DD h:mm a")}
</span>
<span></span>
<span className="text-indigo-300">
Expand Down Expand Up @@ -491,6 +493,54 @@ const ProjectTitle: React.FC<{
);
};

const ProjectMenuItem: React.FC<{
project: IProject;
activeProject: IProject | undefined;
dragParent: number | null;
setDragParent: (i: number | null) => void;
setActiveProject: (i: IProject) => void;
setProjects: (i: IProject[]) => void;
}> = ({
project,
dragParent,
activeProject,
setDragParent,
setActiveProject,
setProjects,
}) => {
return (
<li
key={project.id}
draggable
onDragEnter={() => {
console.log(`drag enter ${project.parent || project.id}`);
setDragParent(project.parent || project.id);
}}
onDragLeave={() => {
console.log(`drag leave ${project.id}`);
setDragParent(null);
}}
onDragEnd={() => {
console.log(
`set ${project.id} parent to ${dragParent}. set ${dragParent} parent to null`,
);
Promise.all([
setProjectParent(project.id, dragParent),
dragParent && setProjectParent(dragParent, null),
]).then(() => {
getProjects().then(setProjects);
});
}}
onClick={() => {
setActiveProject(project);
}}
className={`${activeProject?.id === project.id && "bg-zinc-600"} px-2 hover:bg-zinc-700 ${project.parent ? "pl-8" : ""}`}
>
{project.name || "Untitled Project"}
</li>
);
};

function App() {
const { projects, setProjects, activeProject, setActiveProject } =
useProjects((s) => s);
Expand Down Expand Up @@ -567,6 +617,8 @@ function App() {
});
}, []);

const [dragParent, setDragParent] = useState<number | null>(null);

return (
<div className="flex h-[100vh] w-full flex-row justify-start align-middle font-sans text-stone-800">
<div className="flex h-[100vh] w-[15rem] flex-grow-0 flex-col gap-2 bg-zinc-800 py-2 text-stone-300">
Expand All @@ -586,15 +638,17 @@ function App() {
</li>
<hr />
{projects.map((project) => (
<li
<ProjectMenuItem
key={project.id}
onClick={() => {
setActiveProject(project);
{...{
project,
activeProject,
dragParent,
setDragParent,
setActiveProject,
setProjects,
}}
className={`${activeProject?.id === project.id && "bg-zinc-600"} px-2 hover:bg-zinc-700`}
>
{project.name || "Untitled Project"}
</li>
/>
))}
</ul>
</div>
Expand Down
19 changes: 17 additions & 2 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dayjs, { Dayjs } from "dayjs";
export interface IProject {
id: number;
name: string;
parent: number | null;
}

export interface IEntry {
Expand Down Expand Up @@ -34,7 +35,12 @@ export const getDB = async () => {

export const getProjects = async () => {
const db = await getDB();
const result = await db.select<IProject[]>("SELECT * FROM projects");
const q = `
select *
from projects
order by coalesce(parent, id), parent
`;
const result = await db.select<IProject[]>(q);
return result;
};

Expand All @@ -61,6 +67,15 @@ export const deleteProject = async (id: number) => {
return result;
};

export const setProjectParent = async (id: number, parent: number | null) => {
const db = await getDB();
const result = await db.execute(
"UPDATE projects SET parent = ? WHERE id = ?",
[parent, id],
);
return result;
};

export const getEntries = async (project_id: number) => {
const db = await getDB();
const result = await db.select<IEntry[]>(
Expand All @@ -80,7 +95,7 @@ export const getEntriesOverRange = async (
"select * FROM entries WHERE date_created between ? and ? and project_id = ?;",
[start_date.toISOString(), end_date.toISOString(), project_id],
);

return result;
};

Expand Down

0 comments on commit 76782c6

Please sign in to comment.