Skip to content

[feat] Implement task management system functionality #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1a5ef7e
task functionality for weed and water tasks
SashankBalusu Apr 16, 2025
c1813d1
task functionality for weed and water tasks
SashankBalusu Apr 16, 2025
9284915
Merge
SashankBalusu Apr 16, 2025
94e5dc6
god bless harvest tasks god bless america
SashankBalusu Apr 16, 2025
143c844
bruh
SashankBalusu Apr 17, 2025
62daf19
changes to due date n stuff
kylezryr Apr 18, 2025
eb0e785
this ones for u kyle
SashankBalusu Apr 23, 2025
d55bab5
refactor to tasks table
SashankBalusu Apr 24, 2025
1d270da
why is my local eslint not good
SashankBalusu Apr 24, 2025
4e845dd
task functionality for weed and water tasks
SashankBalusu Apr 16, 2025
bed8564
task functionality for weed and water tasks
SashankBalusu Apr 16, 2025
e323eb9
god bless harvest tasks god bless america
SashankBalusu Apr 16, 2025
413f1de
bruh
SashankBalusu Apr 17, 2025
fef47da
changes to due date n stuff
kylezryr Apr 18, 2025
65223fb
this ones for u kyle
SashankBalusu Apr 23, 2025
1820197
refactor to tasks table
SashankBalusu Apr 24, 2025
73237ba
why is my local eslint not good
SashankBalusu Apr 24, 2025
6649820
fix icon rebase error and run prettier
kylezryr Apr 25, 2025
4c8869d
Merge branch '95-implement-task-management-system-functionality' of h…
SashankBalusu Apr 25, 2025
a7997db
helo
SashankBalusu Apr 25, 2025
6b97a78
task functionality for weed and water tasks
SashankBalusu Apr 16, 2025
25b110a
god bless harvest tasks god bless america
SashankBalusu Apr 16, 2025
d2916f3
bruh
SashankBalusu Apr 17, 2025
2595dcb
changes to due date n stuff
kylezryr Apr 18, 2025
962bd83
this ones for u kyle
SashankBalusu Apr 23, 2025
ee21cd8
refactor to tasks table
SashankBalusu Apr 24, 2025
c4d0888
why is my local eslint not good
SashankBalusu Apr 24, 2025
0e272b0
task functionality for weed and water tasks
SashankBalusu Apr 16, 2025
a8f9087
task functionality for weed and water tasks
SashankBalusu Apr 16, 2025
647820e
god bless harvest tasks god bless america
SashankBalusu Apr 16, 2025
16fdf50
bruh
SashankBalusu Apr 17, 2025
65d4bf8
changes to due date n stuff
kylezryr Apr 18, 2025
a792254
this ones for u kyle
SashankBalusu Apr 23, 2025
a7ab313
refactor to tasks table
SashankBalusu Apr 24, 2025
f540b77
why is my local eslint not good
SashankBalusu Apr 24, 2025
5d4b7e9
fix icon rebase error and run prettier
kylezryr Apr 25, 2025
fe64e3c
helo
SashankBalusu Apr 25, 2025
722db88
tspmo
SashankBalusu Apr 25, 2025
30c32af
Merge branch '95-implement-task-management-system-functionality' of h…
SashankBalusu Apr 25, 2025
3052e57
convert due date to dayjs to avoid timezone issues
kylezryr Apr 27, 2025
3a20e28
lint
kylezryr Apr 27, 2025
6cd80c8
remove unneeded columns in user_plants
kylezryr Apr 27, 2025
967bdd9
lint
kylezryr Apr 27, 2025
eb3a734
revert due date to use Date
kylezryr Apr 27, 2025
e7e83d9
remove console.log
kylezryr Apr 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion api/supabase/queries/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlantTip } from '@/types/schema';
import { PlantTip, UserPlant } from '@/types/schema';
import supabase from '../createClient';

//quick lil documentation drop:
Expand Down Expand Up @@ -42,3 +42,64 @@ export const getDailyPlantTip = async (): Promise<PlantTip | null> => {
const dayInCycle = new Date().getDate() % cycleLength;
return shuffledTips[dayInCycle];
};

export async function getPendingTasks(userId: string): Promise<UserPlant[]> {
const { data, error } = await supabase
.from('user_plants')
.select('*')
.eq('user_id', userId)
.is('date_removed', null)
.not('last_watered', 'is', null)
.not('last_weeded', 'is', null);

if (error) {
console.error('Error fetching user plants:', error);
}

return data ?? [];
}

export async function updateDate(
id: string,
newDate: Date,
taskType: string,
isPrevious: boolean = false,
) {
console.log(id, newDate, taskType, isPrevious);

// Use the isPrevious flag to choose the proper mapping.
const fieldMap: Record<string, string> = {
water: isPrevious ? 'previous_last_watered' : 'last_watered',
weed: isPrevious ? 'previous_last_weeded' : 'last_weeded',
};

const fieldToUpdate = fieldMap[taskType];
if (!fieldToUpdate) {
console.error(`Invalid task type: ${taskType}`);
return;
}

const { data, error } = await supabase
.from('user_plants')
.update({ [fieldToUpdate]: newDate })
.eq('id', id)
.select();

if (error) {
console.error(`Error updating ${fieldToUpdate} date:`, error);
}
return data;
}

export async function setDueDate(new_date: Date, id: string) {
const { data, error } = await supabase
.from('user_plants')
.update({ due_date: new_date })
.eq('id', id);

if (error) {
console.error(`Error updating due date:`, error);
}

return data;
}
14 changes: 12 additions & 2 deletions api/supabase/queries/userPlants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import supabase from '../createClient';
export async function insertUserPlants(
userPlants: Omit<
UserPlant,
'id' | 'date_removed' | 'recent_harvest' | 'num_harvested'
'id' | 'date_removed' | 'recent_harvest' | 'num_harvested' | 'due_date'
>[],
) {
const { error } = await supabase.from('user_plants').insert(userPlants);
Expand Down Expand Up @@ -79,8 +79,18 @@ export async function increaseHarvestedByOne(id: UUID) {
}
}

export async function decreaseHarvestedByOne(id: UUID) {
const { error } = await supabase.rpc('decrement_num_harvested', {
row_id: id,
});

if (error) {
throw new Error('Error decrementing:', error);
}
}

export async function setRecentHarvestDate(
date: string,
date: string | null,
id: UUID,
): Promise<void> {
const { error } = await supabase
Expand Down
15 changes: 14 additions & 1 deletion app/add-details/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export default function Home() {
updatedDetails[index] = {
...updatedDetails[index],
[field]: value,
water_frequency: plantsToAdd[index].water_frequency,
weeding_frequency: plantsToAdd[index].weeding_frequency,
plant_name: plantsToAdd[index].plant_name,
harvest_season: plantsToAdd[index].harvest_season,
};
setDetails(updatedDetails);
}
Expand All @@ -126,12 +130,21 @@ export default function Home() {
try {
const completedDetails: Omit<
UserPlant,
'id' | 'date_removed' | 'recent_harvest' | 'num_harvested'
'id' | 'date_removed' | 'recent_harvest' | 'num_harvested' | 'due_date'
>[] = details.map(detail => ({
user_id: userId,
plant_id: detail.plant_id!,
date_added: detail.date_added!,
planting_type: detail.planting_type!,
water_frequency: detail.water_frequency!,
weeding_frequency: detail.weeding_frequency!,
last_watered: getDefaultDate(),
last_weeded: getDefaultDate(),
plant_name: detail.plant_name!,
date_added_to_db: getDefaultDate(),
previous_last_watered: getDefaultDate(),
previous_last_weeded: getDefaultDate(),
harvest_season: detail.harvest_season!,
}));
await insertUserPlants(completedDetails);
router.push('/view-plants');
Expand Down
Loading