diff --git a/src/app/needs/components/NeedsDisplay.tsx b/src/app/needs/components/NeedsDisplay.tsx index ebe63e6b..d4ec1646 100644 --- a/src/app/needs/components/NeedsDisplay.tsx +++ b/src/app/needs/components/NeedsDisplay.tsx @@ -304,7 +304,7 @@ export default function NeedsDisplay() { className={clsx( "fixed right-4 bottom-24 text-white rounded", hasHighlightedNeeds - ? "bg-twd-primary-purple shadow-twd-primary-purple shadow-glow" + ? "bg-twd-primary-purple" : "bg-gray-400 cursor-not-allowed" )} /> diff --git a/src/app/needs/next-actions/components/NextActionsDisplay.tsx b/src/app/needs/next-actions/components/NextActionsDisplay.tsx index 3a18b571..031ac491 100644 --- a/src/app/needs/next-actions/components/NextActionsDisplay.tsx +++ b/src/app/needs/next-actions/components/NextActionsDisplay.tsx @@ -5,6 +5,8 @@ import { useDatabase } from "@/context/DatabaseContext"; import clsx from "clsx"; import changeCase from "@/lib/utils/changeCase"; import NextActionsSection from "./NextActionsSection"; +import Button from "@/ui/shared/Button"; +import Modal from "@/ui/shared/Modal"; export interface NeedDocument { id: string; @@ -32,14 +34,15 @@ export interface NextActionDocument { export default function NextActionsDisplay() { const database = useDatabase(); const [highlightedNeeds, setHighlightedNeeds] = useState([]); - const [relatedNextActions, setRelatedNextActions] = useState< - NextActionDocument[] - >([]); + const [relatedNextActions, setRelatedNextActions] = useState([]); const [chainEnd, setChainEnd] = useState(0); const [actionState, setActionState] = useState(0); + const [mode, setMode] = useState<"create" | "destroy">("create"); + const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); + const [choppingBlock, setChoppingBlock] = useState(null); - useEffect(() => { - /* Fetch Data */ + + useEffect(() => { /* Fetch Data */ async function fetchData() { const needsDocs = await database.getFromDb("needs"); const allNeeds = needsDocs.map((doc) => doc.toJSON() as NeedDocument); @@ -70,6 +73,10 @@ export default function NextActionsDisplay() { fetchData(); }, [database, chainEnd, actionState]); + useEffect(() => { /* Log Mode Change */ + console.log(`...to ${mode}.`); + }, [mode]) + const priorityGroups = useMemo(() => { if (highlightedNeeds.length === 0) return []; @@ -119,7 +126,7 @@ export default function NextActionsDisplay() { if (highlighted) { const updatedTimestamps = [...action.selectedTimestamps]; updatedTimestamps.pop(); - + await database.updateDocument( collectionName, action.id, @@ -134,17 +141,9 @@ export default function NextActionsDisplay() { action.timestamp ); } else { - // Highlight action: - // Add new selectedTimestamp - const updatedTimestamps = [ - ...action.selectedTimestamps, - new Date().toISOString(), - ]; - - // Find the parent need to copy its selectedExpiry - const parentNeed = highlightedNeeds.find( - (need) => need.id === action.need - ); + const updatedTimestamps = [...action.selectedTimestamps, new Date().toISOString()]; + + const parentNeed = highlightedNeeds.find((need) => need.id === action.need); if (!parentNeed) { console.error("Parent need not found for action:", action); return; @@ -165,7 +164,30 @@ export default function NextActionsDisplay() { ); } - setChainEnd((prev) => prev + 1); + setChainEnd(prev => prev + 1); + }; + + const onDeleteAction = async (action: NextActionDocument) => { + setChoppingBlock(action); + setIsDeleteModalOpen(true); + }; + + const onReallyDeleteAction = async (action: NextActionDocument) => { + await database.deleteFromDb("next_actions", action.id); + + setChoppingBlock(null); + setChainEnd(prev => prev + 1); + }; + + const onToggleMode = () => { + switch(mode) { + case "create": + setMode("destroy"); + break; + case "destroy": + setMode("create"); + break; + } }; const handleAddAction = async (newAction: string, need: NeedDocument) => { @@ -186,59 +208,89 @@ export default function NextActionsDisplay() { } setActionState((prev) => prev + 1); + console.log(`Action State: ${actionState}`); } }; - + return (
- {priorityGroups.length === 0 ? ( -

- You have no unmet needs selected. Review which needs might be unmet - before we can recommend next actions to meet them. -

- ) : ( - priorityGroups.map((group, i) => ( + {priorityGroups.length === 0 + ? (

+ You have no unmet needs selected. Review which needs might be unmet before we can recommend next actions to meet them. +

) + : (priorityGroups.map((group, i) => (
-

+

{changeCase(group.priority.name, "sentence")}

- + {group.needs.map((need) => { const actions = getActionsForNeed(need.id); return (

- To meet a need for {changeCase(need.name, "lower")}, which - actions can you take next? + To meet a need for {changeCase(need.name, "lower")}, which actions can you take next?

- {actions.length > 0 ? ( - - ) : ( -

+ { actions.length > 0 + ? ( + + ) + : (

No next actions available for this need. -

- )} +

) + }
); })}
- )) - )} + ))) + } + +
); -} +} \ No newline at end of file diff --git a/src/app/needs/next-actions/components/NextActionsSection.tsx b/src/app/needs/next-actions/components/NextActionsSection.tsx index 8f7cacca..efaad9d4 100644 --- a/src/app/needs/next-actions/components/NextActionsSection.tsx +++ b/src/app/needs/next-actions/components/NextActionsSection.tsx @@ -12,6 +12,8 @@ interface SectionProps { actions: NextActionDocument[]; onToggleAction: (action: NextActionDocument) => Promise; handleAddAction: (newAction: string, need: NeedDocument) => Promise; + onDeleteAction: (action: NextActionDocument) => Promise; + mode: "create" | "destroy"; } export default function NextActionsSection({ @@ -19,6 +21,8 @@ export default function NextActionsSection({ actions, onToggleAction, handleAddAction, + onDeleteAction, + mode }: SectionProps) { const [modalOpen, setModalOpen] = useState(false); const [newAction, setNewAction] = useState(""); @@ -39,30 +43,31 @@ export default function NextActionsSection({ const highlighted = new Date(action.selectedExpiry) > new Date(); return ( - - ); -} +} \ No newline at end of file