-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic layout * Tweaks * create market from task * Add droplet sound * ui * Assign tasks to users * Show/hide completed tasks * Tweak * Fix categories and tap outside * Use mobile hook * Remove public read policies * Add todo to sitemap * Only admins can assign tasks * Set priorities * Priority styles
- Loading branch information
1 parent
63350e6
commit 61c3d21
Showing
17 changed files
with
1,127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { APIHandler } from './helpers/endpoint' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
|
||
export const createCategory: APIHandler<'create-category'> = async (props, auth) => { | ||
const { name, color } = props | ||
const pg = createSupabaseDirectClient() | ||
|
||
console.log('Creating category', { userId: auth.uid, name, color }) | ||
|
||
const result = await pg.one( | ||
`insert into categories (user_id, name, color) | ||
values ($1, $2, $3) | ||
returning id`, | ||
[auth.uid, name, color] | ||
) | ||
|
||
return { id: result.id } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { APIHandler } from './helpers/endpoint' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
|
||
export const createTask: APIHandler<'create-task'> = async (props, auth) => { | ||
const { | ||
text, | ||
category_id: categoryId, | ||
priority, | ||
assignee_id: assigneeId, | ||
} = props | ||
const pg = createSupabaseDirectClient() | ||
|
||
console.log('Creating task', { | ||
userId: auth.uid, | ||
text, | ||
categoryId, | ||
priority, | ||
assigneeId, | ||
}) | ||
|
||
const result = await pg.one( | ||
`insert into tasks (creator_id, assignee_id, text, category_id, priority) | ||
values ($1, $2, $3, $4, $5) | ||
returning *`, | ||
[auth.uid, assigneeId || auth.uid, text, categoryId, priority] | ||
) | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { APIHandler } from './helpers/endpoint' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
|
||
export const getCategories: APIHandler<'get-categories'> = async (_, auth) => { | ||
const pg = createSupabaseDirectClient() | ||
|
||
console.log('Getting categories for user', auth.uid) | ||
|
||
const categories = await pg.manyOrNone( | ||
`SELECT DISTINCT ON (c.id) c.* | ||
FROM categories c | ||
LEFT JOIN tasks t ON c.id = t.category_id | ||
WHERE c.user_id = $1 | ||
OR t.assignee_id = $1 | ||
ORDER BY c.id, c.display_order, c.created_time`, | ||
[auth.uid] | ||
) | ||
|
||
return { categories } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { APIHandler } from './helpers/endpoint' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
|
||
export const getTasks: APIHandler<'get-tasks'> = async (_, auth) => { | ||
const pg = createSupabaseDirectClient() | ||
|
||
console.log('Getting tasks for user', auth.uid) | ||
|
||
const tasks = await pg.manyOrNone( | ||
`select * | ||
from tasks | ||
where creator_id = $1 or assignee_id = $1 | ||
order by priority, created_time desc`, | ||
[auth.uid] | ||
) | ||
|
||
return { tasks } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { APIHandler } from './helpers/endpoint' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
|
||
export const updateCategory: APIHandler<'update-category'> = async ( | ||
props, | ||
auth | ||
) => { | ||
const { categoryId, name, color, displayOrder, archived } = props | ||
const pg = createSupabaseDirectClient() | ||
|
||
console.log('Updating category', { | ||
categoryId, | ||
name, | ||
color, | ||
displayOrder, | ||
archived, | ||
userId: auth.uid, | ||
}) | ||
|
||
const updates: { [key: string]: any } = {} | ||
if (name !== undefined) updates.name = name | ||
if (color !== undefined) updates.color = color | ||
if (displayOrder !== undefined) updates.display_order = displayOrder | ||
if (archived !== undefined) updates.archived = archived | ||
|
||
const setClauses = Object.entries(updates) | ||
.map(([key], i) => `${key} = $${i + 3}`) | ||
.join(', ') | ||
|
||
await pg.none( | ||
`update categories | ||
set ${setClauses} | ||
where id = $1 and user_id = $2`, | ||
[categoryId, auth.uid, ...Object.values(updates)] | ||
) | ||
|
||
return { success: true } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { log } from 'shared/utils' | ||
import { APIError, APIHandler } from './helpers/endpoint' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
|
||
export const updateTask: APIHandler<'update-task'> = async (props, auth) => { | ||
const { id, text, completed, priority, category_id, archived, assignee_id } = | ||
props | ||
const pg = createSupabaseDirectClient() | ||
log('Updating task', props) | ||
|
||
// Build update fields dynamically | ||
const updates: { [key: string]: any } = {} | ||
if (completed !== undefined) updates.completed = completed | ||
if (priority !== undefined) updates.priority = priority | ||
if (category_id !== undefined) updates.category_id = category_id | ||
if (text !== undefined) updates.text = text | ||
if (archived !== undefined) updates.archived = archived | ||
if (assignee_id !== undefined) updates.assignee_id = assignee_id | ||
const setClauses = Object.entries(updates) | ||
.map(([key], i) => `${key} = $${i + 3}`) | ||
.join(', ') | ||
|
||
const result = await pg.oneOrNone( | ||
`update tasks | ||
set ${setClauses} | ||
where id = $1 and (creator_id = $2 or assignee_id = $2) | ||
returning id, priority, category_id, text, completed, assignee_id | ||
`, | ||
[id, auth.uid, ...Object.values(updates)] | ||
) | ||
|
||
if (!result) { | ||
throw new APIError(404, 'Task not found or unauthorized') | ||
} | ||
|
||
return { success: true } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
create table if not exists | ||
categories ( | ||
id bigint primary key generated always as identity not null, | ||
user_id text not null, | ||
name text not null, | ||
color text, | ||
display_order integer default 0 not null, | ||
archived boolean default false not null, | ||
created_time timestamp with time zone default now() not null | ||
); | ||
|
||
-- Row Level Security | ||
alter table categories enable row level security; | ||
|
||
-- Indexes | ||
create index categories_user_id_idx on categories (user_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
create table if not exists | ||
tasks ( | ||
id bigint primary key generated always as identity not null, | ||
creator_id text not null references users (id), | ||
assignee_id text not null references users (id), | ||
category_id bigint not null, | ||
text text not null, | ||
completed boolean default false not null, | ||
priority integer default 0 not null, | ||
archived boolean default false not null, | ||
created_time timestamp with time zone default now() not null | ||
); | ||
|
||
-- Row Level Security | ||
alter table tasks enable row level security; | ||
|
||
-- Indexes | ||
create index tasks_creator_id_idx on tasks (creator_id); | ||
|
||
create index tasks_assignee_id_idx on tasks (assignee_id); | ||
|
||
create index tasks_category_id_idx on tasks (category_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export type TaskCategory = { | ||
id: number | ||
name: string | ||
color?: string | ||
displayOrder: number | ||
archived?: boolean | ||
} | ||
|
||
export type Task = { | ||
id: number | ||
creator_id: string | ||
assignee_id: string | ||
text: string | ||
completed: boolean | ||
category_id: number // -1 for inbox | ||
created_time: number | ||
priority: number | ||
archived: boolean | ||
} |
Oops, something went wrong.