Skip to content

Commit

Permalink
Problem: can claim problems with open children
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Nov 11, 2023
1 parent c667c54 commit 34d0ac9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/components/problems/LogNewProblemModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
onMount(()=>{
if (existing){
newProblem = existing.Copy()
} else {
} else if (parent) {
newProblem = new Problem()
newProblem.Parents.add(parent.UID)
}
})
Expand Down Expand Up @@ -82,13 +83,18 @@
rocket: newProblem.Rocket, //todo check parent problem's rocket and use that here
});
e.tags.push(["text", newProblem.Title, "tldr"]);
e.tags.push(["text", newProblem.Summary, "paragraph"]);
e.tags.push(["text", newProblem.FullText, "page"]);
if (newProblem.Summary) {
e.tags.push(["text", newProblem.Summary, "paragraph"]);
}
if (newProblem.FullText) {
e.tags.push(["text", newProblem.FullText, "page"]);
}
newProblem.Parents.forEach(p=>{
e.tags.push(["e", p, "", "parent"]);
})
if (parent && !existing) {
e.tags.push(["new"]);
}
if (!parent && existing) {
e.tags.push(["e", existing.UID, "problem"])
Expand Down
14 changes: 14 additions & 0 deletions src/lib/stores/nostrocket_state/soft_state/simplifiedProblems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { labelledTag } from "$lib/helpers/shouldBeInNDK";
import type { NDKEvent } from "@nostr-dev-kit/ndk";
import { nostrocketIgnitionEvent, rootProblem } from "../../../../settings";
import { Problem, type Nostrocket } from "../types";
import { consensusTipState } from "../master_state";
import { get } from "svelte/store";
import { tr } from "date-fns/locale";

export function HandleProblemEvent(
ev: NDKEvent,
Expand Down Expand Up @@ -72,6 +75,7 @@ function handleProblemStatusChangeEvent(
return "you cannot mark this problem as patched unless you are the one who claimed it";
}
if (newStatus == "claimed") {
if (hasOpenChildren(problem, state)) {return "this problem has open children, it cannot be claimed"}
state.Problems.forEach((p) => {
if (p.Status == "claimed" && p.ClaimedBy == ev.pubkey) {
return (
Expand Down Expand Up @@ -226,6 +230,16 @@ function populateChildren(problem: Problem, state: Nostrocket) {
});
}

export function hasOpenChildren(problem:Problem, state:Nostrocket):boolean {
let has = false
if (!state) {state = get(consensusTipState)}
problem?.Children.forEach(p=>{
if (state.Problems.get(p)?.Status != "closed") {
has = true
}
})
return has
}
//// Legacy stuff for reference, leave here for G to delete:
// function updateProblemWithNewHead(
// current: Problem,
Expand Down
6 changes: 3 additions & 3 deletions src/routes/problems/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { AcceleratedComputing, DesignLeadership, DoNot, Idea, Management } from "carbon-pictograms-svelte";
import { get } from "svelte/store";
import LogNewProblemModal from "../../../components/problems/LogNewProblemModal.svelte";
import { HandleProblemEvent } from "$lib/stores/nostrocket_state/soft_state/simplifiedProblems";
import { HandleProblemEvent, hasOpenChildren } from "$lib/stores/nostrocket_state/soft_state/simplifiedProblems";
let problem: Problem | undefined;
let createdBy: NDKUserProfile | undefined;
Expand Down Expand Up @@ -124,12 +124,12 @@
<p
style="display: flex; align-items: center; text-transform: capitalize"
>
{#if problem?.Status == "open" && problem.Children.size > 0}<span
{#if problem?.Status == "open" && hasOpenChildren(problem, $consensusTipState)}<span
style="color:blueviolet"
><Management /> HAS OPEN CHILDREN</span
>
{/if}
{#if problem?.Status == "open" && problem.Children.size == 0}<span
{#if problem?.Status == "open" && !hasOpenChildren(problem, $consensusTipState)}<span
style="color:green"><Idea /> OPEN AND CAN BE CLAIMED</span
>
{/if}
Expand Down

0 comments on commit 34d0ac9

Please sign in to comment.