diff --git a/classes/activities/class.circle-of-support.php b/classes/activities/class.circle-of-support.php index 777539526..d359a9da8 100644 --- a/classes/activities/class.circle-of-support.php +++ b/classes/activities/class.circle-of-support.php @@ -88,9 +88,6 @@ public function removeConnectionFromCommunity($connectionId, $communityId) public function deleteConnection($connectionId) { - if (!isset($this->current['connections']->$connectionId)) { - return; - } $this->removeConnectionFromCircles($connectionId); foreach ($this->current['communities'] as $key => $value) { @@ -100,7 +97,9 @@ public function deleteConnection($connectionId) $this->removeConnectionFromCommunity($connectionId, $key); } - unset($this->current['connections']->$connectionId); + if (isset($this->current['connections']->$connectionId)) { + unset($this->current['connections']->$connectionId); + } } public function updateConnection($id, $connection) diff --git a/classes/class.tapestry-node.php b/classes/class.tapestry-node.php index f17b31ed5..591b844db 100644 --- a/classes/class.tapestry-node.php +++ b/classes/class.tapestry-node.php @@ -46,7 +46,6 @@ class TapestryNode implements ITapestryNode private $license; private $references; private $mapCoordinates; - private $isDyad; private $popup; /** @@ -99,7 +98,6 @@ public function __construct($tapestryPostId = 0, $nodeMetaId = 0) 'lat' => '', 'lng' => '', ]; - $this->isDyad = false; $this->popup = null; if (TapestryHelpers::isValidTapestryNode($this->nodeMetaId)) { @@ -208,9 +206,6 @@ public function set($node) if (isset($node->hideTitle) && is_bool($node->hideTitle)) { $this->hideTitle = $node->hideTitle; } - if (isset($node->isDyad) && is_bool($node->isDyad)) { - $this->isDyad = $node->isDyad; - } if (isset($node->hideProgress) && is_bool($node->hideProgress)) { $this->hideProgress = $node->hideProgress; } @@ -304,7 +299,7 @@ public function removeConditionsById($nodeId) } } - public function getLockedState() + public function getLockedState($userId = 0) { $conditions = $this->conditions; $userProgress = new TapestryUserProgress($this->tapestryPostId, $this->nodeMetaId); @@ -316,8 +311,7 @@ public function getLockedState() foreach ($conditions as $condition) { switch ($condition->type) { case ConditionTypes::NODE_COMPLETED: - $conditionProgress = new TapestryUserProgress($this->tapestryPostId, $condition->nodeId); - if ($conditionProgress->isCompleted()) { + if ($userId && $userProgress->isCompleted($condition->nodeId, $userId)) { $condition->fulfilled = true; } break; @@ -339,9 +333,9 @@ public function getLockedState() return $conditions; } - public function isLocked() + public function isLocked($userId = 0) { - $conditions = $this->getLockedState(); + $conditions = $this->getLockedState($userId); $numFulfilled = 0; foreach ($conditions as $condition) { @@ -389,11 +383,6 @@ public function isAuthor($userId = 0) return $nodeMeta->author->id == $userId; } - public function isDyad() - { - return $this->isDyad; - } - public function addReview($comments) { if (NodeStatus::PUBLISH === $this->status) { @@ -588,7 +577,6 @@ private function _formNode() 'license' => $this->license, 'references' => $this->references, 'mapCoordinates' => $this->mapCoordinates, - 'isDyad' => $this->isDyad, 'popup' => $this->popup, ]; } diff --git a/classes/class.tapestry-user-progress.php b/classes/class.tapestry-user-progress.php index 6320d37df..e3b8eb24a 100644 --- a/classes/class.tapestry-user-progress.php +++ b/classes/class.tapestry-user-progress.php @@ -13,8 +13,6 @@ class TapestryUserProgress implements ITapestryUserProgress private $_userId = null; private $postId; private $nodeMetaId; - private $_dyadLinkedUserId = null; - private $node; /** * Constructor. @@ -26,27 +24,9 @@ class TapestryUserProgress implements ITapestryUserProgress */ public function __construct($postId = null, $nodeMetaId = null) { + $this->_userId = apply_filters('determine_current_user', false); $this->postId = $postId; $this->nodeMetaId = $nodeMetaId; - - if ($nodeMetaId) { - $this->node = new TapestryNode($postId = null, $nodeMetaId = null); - } - - $this->_userId = apply_filters('determine_current_user', false); - if ($this->_userId) { - global $TYDE_DYAD_ROLES; - $isDyadUser = array_intersect(get_userdata($this->_userId)->roles, array_keys($TYDE_DYAD_ROLES)); - if ($isDyadUser) { - $linkedUserId = get_user_meta($this->_userId, 'linked_dyad_user_id', true); - if ($linkedUserId) { - if ($this->node && $this->node->isDyad()) { - $this->_userId = $linkedUserId; - } - $this->_dyadLinkedUserId = $linkedUserId; - } - } - } } /** @@ -62,7 +42,7 @@ public function get() $tapestry = new Tapestry($this->postId); $nodeIds = $tapestry->getNodeIds(); - return $this->_getUserProgress($nodeIds); + return $this->_getUserProgress($nodeIds, $this->_userId); } /** @@ -75,7 +55,6 @@ public function get() public function updateUserProgress($progressValue) { $this->_checkPostId(); - $this->_checkProgressAbility(); if (null !== $progressValue) { $progressValue = floatval($progressValue); @@ -97,7 +76,6 @@ public function updateUserProgress($progressValue) public function complete() { $this->_checkPostId(); - $this->_checkProgressAbility(); $this->_complete(); } @@ -112,7 +90,6 @@ public function complete() public function completeQuestion($questionId, $answerType, $answerData) { $this->_checkPostId(); - $this->_checkProgressAbility(); $this->_completeQuestion($questionId, $answerType, $answerData); } @@ -165,19 +142,8 @@ public function getAvatar() return $this->_getAvatar(); } - public function isCompleted($nodeId = null, $userId = null) + public function isCompleted($nodeId, $userId) { - if (!$nodeId) { - $nodeId = $this->nodeMetaId; - } - if (!$userId) { - $userId = $this->_userId; - } - - if (!$userId) { - return false; - } - $nodeMetadata = get_metadata_by_mid('post', $nodeId)->meta_value; $completed_value = get_user_meta($userId, 'tapestry_'.$this->postId.'_node_completed_'.$nodeId, true); if (null !== $completed_value) { @@ -232,24 +198,17 @@ private function _completeQuestion($questionId, $answerType, $answerData) update_user_meta($this->_userId, 'tapestry_'.$this->postId.'_'.$this->nodeMetaId.'_question_'.$questionId.'_answers', $userAnswer); } - private function _getUserProgress($nodeIdArr) + private function _getUserProgress($nodeIdArr, $userId) { $progress = new stdClass(); $tapestry = new Tapestry($this->postId); - $nodes = $tapestry->setUnlocked($nodeIdArr, $this->_userId); + $nodes = $tapestry->setUnlocked($nodeIdArr, $userId); // Build json object for frontend e.g. {0: 0.1, 1: 0.2} where 0 and 1 are the node IDs foreach ($nodes as $node) { $nodeId = $node->id; - $userId = $this->_userId; - - // Use linked user's progress if the user is a dyad and this node is a dyad node - if ($node->isDyad && $this->_dyadLinkedUserId) { - $userId = $this->_dyadLinkedUserId; - } - $progress_value = get_user_meta($userId, 'tapestry_'.$this->postId.'_progress_node_'.$nodeId, true); $progress->$nodeId = new stdClass(); if (null !== $progress_value) { @@ -262,10 +221,6 @@ private function _getUserProgress($nodeIdArr) $progress->$nodeId->conditions = $node->conditions; $progress->$nodeId->unlocked = $node->unlocked; - if ($node->isDyad && $this->_dyadLinkedUserId) { - $progress->$nodeId->node = $node; - } - if ($node->accessible) { $progress->$nodeId->content = [ 'typeData' => $node->typeData, @@ -401,11 +356,6 @@ private function _checkPostId() } } - private function _checkProgressAbility() - { - return $this->_dyadLinkedUserId && $this->node && $this->node->isDyad(); - } - private function _isValidTapestryPost() { // post ID exists in db diff --git a/classes/class.tapestry.php b/classes/class.tapestry.php index 8a3dd3c08..2d35c0f89 100644 --- a/classes/class.tapestry.php +++ b/classes/class.tapestry.php @@ -342,9 +342,9 @@ public function isEmpty() return empty($this->rootId); } - public function setUnlocked($nodeIds) + public function setUnlocked($nodeIds, $userId = 0) { - $nodes = $this->_setAccessibleStatus($nodeIds); + $nodes = $this->_setAccessibleStatus($nodeIds, $userId); return array_map( function ($nodeData) { @@ -354,7 +354,6 @@ function ($nodeData) { $data->accessible = $nodeData->accessible; $data->conditions = $nodeData->conditions; $data->unlocked = $nodeData->unlocked; - $data->isDyad = $nodeData->isDyad; return $data; }, @@ -409,17 +408,16 @@ public function export() ]; } - private function _setAccessibleStatus($nodes) + private function _setAccessibleStatus($nodes, $userId) { $newNodes = array_map( - function ($nodeId) { + function ($nodeId) use ($userId) { $node = new TapestryNode($this->postId, $nodeId); $data = new stdClass(); $data->id = $nodeId; $data->accessible = false; - $data->unlocked = !$node->isLocked(); - $data->conditions = $node->getLockedState(); - $data->isDyad = $node->isDyad(); + $data->unlocked = !$node->isLocked($userId); + $data->conditions = $node->getLockedState($userId); return $data; }, @@ -433,14 +431,13 @@ function ($nodeId) { break; } } - $this->_recursivelySetAccessibleAndDyad($root, [], [], $newNodes); + $this->_recursivelySetAccessible($root, [], $newNodes); } return $newNodes; } - // Note: This also sets the isDyad node recursively - private function _recursivelySetAccessibleAndDyad($node, $visited, $dyadNodes, $nodeList) + private function _recursivelySetAccessible($node, $visited, $nodeList) { if (!isset($node)) { return; @@ -448,25 +445,6 @@ private function _recursivelySetAccessibleAndDyad($node, $visited, $dyadNodes, $ if (!in_array($node, $visited)) { array_push($visited, $node); } - - // If this node is in the list of dyadNodes, mark it as dyad - if (in_array($node->id, $dyadNodes)) { - $node->isDyad = true; - if (($key = array_search($node->id, $dyadNodes)) !== false) { - unset($dyadNodes[$key]); - } - } - - // If this node is dyad, save its children to be marked as dyad too - if ($node->isDyad) { - $childNodes = $this->_getNeighbours($node, 'source'); - foreach ($childNodes as $childNode) { - if (!in_array($childNode, $dyadNodes)) { - array_push($dyadNodes, $childNode); - } - } - } - $node->accessible = $node->unlocked; if ($node->accessible) { $neighbourIds = $this->_getNeighbours($node); @@ -484,19 +462,18 @@ private function _recursivelySetAccessibleAndDyad($node, $visited, $dyadNodes, $ foreach ($neighbours as $neighbour) { if (!in_array($neighbour, $visited)) { array_push($visited, $neighbour); - $this->_recursivelySetAccessibleAndDyad($neighbour, $visited, $dyadNodes, $nodeList); + $this->_recursivelySetAccessible($neighbour, $visited, $nodeList); } } } } - private function _getNeighbours($node, $from = 'both') + private function _getNeighbours($node) { $neighbourIds = []; foreach ($this->links as $link) { - if ((in_array($from, ['both', 'source']) && $link->source === $node->id) || - (in_array($from, ['both', 'target']) && $link->target === $node->id)) { + if ($link->source === $node->id || $link->target === $node->id) { array_push( $neighbourIds, $link->source === $node->id ? $link->target : $link->source diff --git a/tapestry.php b/tapestry.php index a4e28974c..3af240d58 100644 --- a/tapestry.php +++ b/tapestry.php @@ -16,18 +16,6 @@ // Set this to false if you want to use the Vue build instead of npm dev $TAPESTRY_USE_DEV_MODE = true; -// TYDE settings -$TYDE_YOUTH_ROLES = [ - 'youth' => 'Youth', - 'youth_l2' => 'Youth (Level 2)', - 'youth_l3' => 'Youth (Level 3)', -]; -$TYDE_DYAD_ROLES = [ - 'dyad' => 'Dyad', - 'dyad_l2' => 'Dyad (Level 2)', - 'dyad_l3' => 'Dyad (Level 3)', -]; - /** * Register endpoints. */ @@ -144,16 +132,6 @@ function tapestry_enqueue_vue_app() global $TAPESTRY_VERSION_NUMBER; global $TAPESTRY_USE_DEV_MODE; - global $TYDE_DYAD_ROLES; - $isDyad = wp_get_current_user() && array_intersect(wp_get_current_user()->roles, array_keys($TYDE_DYAD_ROLES)); - $dyadLinkedUser = null; - if ($isDyad) { - $dyadLinkedUserId = get_the_author_meta('linked_dyad_user_id', wp_get_current_user()->ID); - if ($dyadLinkedUserId) { - $dyadLinkedUser = get_user_by('id', $dyadLinkedUserId)->data; - } - } - // register the Vue build script. $vueUrl = $TAPESTRY_USE_DEV_MODE ? 'http://localhost:8080/dist' : plugin_dir_url(__FILE__).'templates/vue/dist'; @@ -184,7 +162,6 @@ function tapestry_enqueue_vue_app() ]), 'nonce' => wp_create_nonce('wp_rest'), 'wpUserId' => apply_filters('determine_current_user', false), - 'dyadLinkedWpUser' => $dyadLinkedUser, 'adminAjaxUrl' => admin_url('admin-ajax.php'), 'file_upload_nonce' => wp_create_nonce('media-form'), 'upload_url' => admin_url('async-upload.php'), @@ -345,70 +322,20 @@ function tapestry_tool_log_event() register_activation_hook(__FILE__, 'add_tyde_roles'); function add_tyde_roles() { - global $TYDE_DYAD_ROLES; - foreach ($TYDE_DYAD_ROLES as $key => $label) { - add_role( - $key, - $label, - [ - 'read' => true, - 'edit_posts' => true, - ] - ); - } - global $TYDE_YOUTH_ROLES; - foreach ($TYDE_YOUTH_ROLES as $key => $label) { - add_role( - $key, - $label, - [ - 'read' => true, - 'edit_posts' => true, - ] - ); - } -} - -/** - * Show the youth user id input if the user is a dyad. - */ -function add_dyad_youth_user_field($user) -{ - global $TYDE_DYAD_ROLES; - $isDyadUser = array_intersect($user->roles, array_keys($TYDE_DYAD_ROLES)); - - if ($isDyadUser) : ?> - - - - - -
-
- -
-roles, array_keys($TYDE_DYAD_ROLES)); - - if ($isDyadUser) { - $linked_dyad_user_id = intval($_POST['linked_dyad_user_id']); - update_user_meta($user_id, 'linked_dyad_user_id', $linked_dyad_user_id); - } -} -add_action('personal_options_update', 'save_dyad_youth_user_field'); -add_action('edit_user_profile_update', 'save_dyad_youth_user_field'); \ No newline at end of file + add_role( + 'dyad', + 'Dyad', + [ + 'read' => true, + 'edit_posts' => true, + ] + ); + add_role( + 'youth', + 'Youth', + [ + 'read' => true, + 'edit_posts' => true, + ] + ); +} \ No newline at end of file diff --git a/templates/vue/src/assets/add-connection-to-circle.gif b/templates/vue/src/assets/add-connection-to-circle.gif new file mode 100644 index 000000000..22962ecaa Binary files /dev/null and b/templates/vue/src/assets/add-connection-to-circle.gif differ diff --git a/templates/vue/src/assets/circle-selections.gif b/templates/vue/src/assets/circle-selections.gif new file mode 100644 index 000000000..a8ed69f32 Binary files /dev/null and b/templates/vue/src/assets/circle-selections.gif differ diff --git a/templates/vue/src/components/Lightbox/index.vue b/templates/vue/src/components/Lightbox/index.vue index 61d172689..40fc6e26c 100644 --- a/templates/vue/src/components/Lightbox/index.vue +++ b/templates/vue/src/components/Lightbox/index.vue @@ -106,15 +106,11 @@ export default { }, computed: { ...mapState(["h5pSettings", "rootId", "settings"]), - ...mapGetters(["getNode", "getParent", "isMultiContent", "isMultiContentRow"]), + ...mapGetters(["getNode", "isMultiContent", "isMultiContentRow"]), node() { const node = this.getNode(this.nodeId) return node }, - parentNode() { - const parentNodeId = this.getParent(this.node.id) - return this.getNode(parentNodeId) - }, canSkip() { return this.node.completed || this.node.skippable !== false }, @@ -301,16 +297,9 @@ export default { this.close() }, close() { - let selectedNode = this.nodeId - if ( - this.parentNode?.mediaType === "multi-content" && - this.parentNode?.presentationStyle === "unit" - ) { - selectedNode = this.parentNode.id - } this.$router.push({ name: names.APP, - params: { nodeId: selectedNode }, + params: { nodeId: this.nodeId }, query: this.$route.query, }) }, diff --git a/templates/vue/src/components/Lightbox/media/ActivityMedia/index.vue b/templates/vue/src/components/Lightbox/media/ActivityMedia/index.vue index 2365ba690..2c9fd6f56 100644 --- a/templates/vue/src/components/Lightbox/media/ActivityMedia/index.vue +++ b/templates/vue/src/components/Lightbox/media/ActivityMedia/index.vue @@ -1,17 +1,6 @@ @@ -155,6 +186,15 @@ export default { overflow: hidden; } +.disabled { + opacity: 0.5; + &:hover { + cursor: not-allowed; + stroke: #999; + stroke-width: 6; + } +} + .contents { height: 100%; } diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/AddConfirmation.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/AddConfirmation.vue similarity index 100% rename from templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/AddConfirmation.vue rename to templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/AddConfirmation.vue diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/AddConfirmationCircles.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/AddConfirmationCircles.vue new file mode 100644 index 000000000..00901a118 --- /dev/null +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/AddConfirmationCircles.vue @@ -0,0 +1,80 @@ + + + + + diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/CircleSelection.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/CircleSelection.vue new file mode 100644 index 000000000..b4260c3f8 --- /dev/null +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/CircleSelection.vue @@ -0,0 +1,42 @@ + + + diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/FinishViewCircles.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/FinishViewCircles.vue new file mode 100644 index 000000000..320a208eb --- /dev/null +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/FinishViewCircles.vue @@ -0,0 +1,34 @@ + + + diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/LetsAddConnections.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/LetsAddConnections.vue new file mode 100644 index 000000000..3d6477d81 --- /dev/null +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/LetsAddConnections.vue @@ -0,0 +1,36 @@ + + + diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveBetweenCircles.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveBetweenCircles.vue new file mode 100644 index 000000000..649c331f7 --- /dev/null +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveBetweenCircles.vue @@ -0,0 +1,38 @@ + + + diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveConnectionsCircles.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveConnectionsCircles.vue new file mode 100644 index 000000000..7a29cf58a --- /dev/null +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveConnectionsCircles.vue @@ -0,0 +1,43 @@ + + + diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveConnectionsToCircleFinish.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveConnectionsToCircleFinish.vue new file mode 100644 index 000000000..8ffcf02dc --- /dev/null +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/MoveConnectionsToCircleFinish.vue @@ -0,0 +1,36 @@ + + + diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/ObFinishView.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/ObFinishView.vue similarity index 85% rename from templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/ObFinishView.vue rename to templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/ObFinishView.vue index 475f46a57..94d819572 100644 --- a/templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/ObFinishView.vue +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/ObFinishView.vue @@ -32,15 +32,25 @@ - + Continue → + + Done +

@@ -66,6 +76,9 @@ export default { connections: { require: true, }, + circleViewEnabled: { + require: true, + }, }, computed: { visibleConnections() { diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/Tooltip.vue b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/Tooltip.vue similarity index 67% rename from templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/Tooltip.vue rename to templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/Tooltip.vue index 52861804e..96ac1e323 100644 --- a/templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/Tooltip.vue +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/Tooltip.vue @@ -2,18 +2,24 @@

diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/onboarding.config.js b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/onboarding.config.js similarity index 100% rename from templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/onboarding.config.js rename to templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/onboarding.config.js diff --git a/templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/onboardingMachine.js b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/onboardingMachine.js similarity index 59% rename from templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/onboardingMachine.js rename to templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/onboardingMachine.js index 1f259ddca..9fe441720 100644 --- a/templates/vue/src/components/tyde/activities/CircleOfSupport/CommunityView/onboarding/onboardingMachine.js +++ b/templates/vue/src/components/tyde/activities/CircleOfSupport/onboarding/onboardingMachine.js @@ -2,9 +2,16 @@ import { createMachine } from "xstate" export const OnboardingStates = { Welcome: "Welcome", - AddMoreConfirmation: "AddMoreConfirmation", AddLaterTooltip: "AddLaterTooltip", AddAnotherTooltip: "AddAnotherTooltip", + ToggleRingsTooltip: "ToggleRingsTooltip", + MoveConnections: "MoveConnections", + LetsAddConnections: "LetsAddConnections", + WaitToOpenConnectionsTab: "WaitToOpenConnectionsTab", + WaitForConnectionTabToClose: "WaitForConnectionTabToClose", + MoveConnectionToCirclesFinish: "MoveConnectionToCirclesFinish", + MoveBetweenCircles: "MoveBetweenCircles", + AddMoreConfirmation: "AddMoreConfirmation", Form: "Form", FormClosed: "FormClosed", Finish: "Finish", @@ -15,6 +22,7 @@ const Events = { Empty: "Empty", NoUserCommunities: "NoUserCommunities", NoConnections: "NoConnections", + NoConnectionsInCircle: "NoConnectionsInCircle", Done: "Done", Continue: "Continue", AddLater: "AddLater", @@ -30,7 +38,7 @@ export const OnboardingEvents = Events * using xstate. */ const onboardingMachine = createMachine({ - id: "CommunityViewOnboarding", + id: "CoSOnboarding", initial: "Idle", states: { Idle: { @@ -38,6 +46,7 @@ const onboardingMachine = createMachine({ [Events.Empty]: "#Communities.Welcome", [Events.NoUserCommunities]: "#Communities.AddMoreConfirmation", [Events.NoConnections]: "#Connections.AddMoreConfirmation", + [Events.NoConnectionsInCircle]: "#Circles.Welcome", [Events.Continue]: "#Connections", [Events.Done]: OnboardingStates.Complete, }, @@ -88,7 +97,7 @@ const onboardingMachine = createMachine({ AddMoreConfirmation: { on: { [Events.AddAnother]: OnboardingStates.AddAnotherTooltip, - [Events.AddLater]: "#Complete", + [Events.AddLater]: "#Circles", }, }, AddAnotherTooltip: { @@ -108,6 +117,64 @@ const onboardingMachine = createMachine({ }, }, Finish: { + on: { + [Events.Continue]: "#Circles", + [Events.Done]: "#Complete", + }, + }, + }, + }, + Circles: { + id: "Circles", + initial: OnboardingStates.Welcome, + states: { + Welcome: { + on: { + [Events.Continue]: OnboardingStates.LetsAddConnections, + }, + }, + LetsAddConnections: { + on: { + [Events.Continue]: OnboardingStates.AddAnotherTooltip, + }, + }, + AddAnotherTooltip: { + on: { + [Events.Continue]: OnboardingStates.WaitToOpenConnectionsTab, + }, + }, + WaitToOpenConnectionsTab: { + on: { + [Events.Continue]: OnboardingStates.MoveConnections, + }, + }, + MoveConnections: { + on: { + [Events.Continue]: OnboardingStates.WaitForConnectionTabToClose, + }, + }, + WaitForConnectionTabToClose: { + on: { + [Events.Continue]: OnboardingStates.MoveConnectionToCirclesFinish, + }, + }, + MoveConnectionToCirclesFinish: { + on: { + [Events.Continue]: OnboardingStates.MoveBetweenCircles, + }, + }, + MoveBetweenCircles: { + on: { + [Events.Continue]: OnboardingStates.ToggleRingsTooltip, + }, + }, + ToggleRingsTooltip: { + on: { + [Events.Continue]: OnboardingStates.Finish, + }, + }, + Finish: { + type: "final", on: { [Events.Done]: "#Complete", }, diff --git a/templates/vue/src/services/wp.js b/templates/vue/src/services/wp.js index e5f881539..95d4907d2 100644 --- a/templates/vue/src/services/wp.js +++ b/templates/vue/src/services/wp.js @@ -27,5 +27,3 @@ export const isCurrentUser = id => parseInt(id) === wpData.currentUser.ID export const isLoggedIn = () => Boolean(wpData.currentUser.ID) export const canEditTapestry = () => wpData.wpCanEditTapestry === "1" - -export const dyadLinkedUser = () => wpData.dyadLinkedWpUser diff --git a/templates/vue/src/store/actions.js b/templates/vue/src/store/actions.js index b65ae78d3..d113f4768 100644 --- a/templates/vue/src/store/actions.js +++ b/templates/vue/src/store/actions.js @@ -116,23 +116,19 @@ export async function updateLockedStatus({ commit, getters, dispatch }) { } } -export async function updateNodeProgress({ commit, getters, dispatch }, payload) { +export async function updateNodeProgress({ commit, dispatch }, payload) { try { const { id, progress } = payload - const node = getters.getNode(id) - - if (!Helpers.nodeAndUserAreDyad(node)) { - if (!wp.isLoggedIn()) { - const progressObj = JSON.parse(localStorage.getItem(LOCAL_PROGRESS_ID)) - const nodeProgress = progressObj[id] || {} - nodeProgress.progress = progress - localStorage.setItem(LOCAL_PROGRESS_ID, JSON.stringify(progressObj)) - } else { - await client.updateUserProgress(id, progress) - } - commit("updateNodeProgress", { id, progress }) + if (!wp.isLoggedIn()) { + const progressObj = JSON.parse(localStorage.getItem(LOCAL_PROGRESS_ID)) + const nodeProgress = progressObj[id] || {} + nodeProgress.progress = progress + localStorage.setItem(LOCAL_PROGRESS_ID, JSON.stringify(progressObj)) + } else { + await client.updateUserProgress(id, progress) } + commit("updateNodeProgress", { id, progress }) } catch (error) { dispatch("addApiError", error) } @@ -156,32 +152,30 @@ export async function updateNodeCoordinates( export async function completeNode(context, nodeId) { const { commit, dispatch, getters } = context - const node = getters.getNode(nodeId) - if (!Helpers.nodeAndUserAreDyad(node)) { - try { - if (!wp.isLoggedIn()) { - const progressObj = JSON.parse(localStorage.getItem(LOCAL_PROGRESS_ID)) - const nodeProgress = progressObj[nodeId] || {} - nodeProgress.completed = true - localStorage.setItem(LOCAL_PROGRESS_ID, JSON.stringify(progressObj)) - } else { - await client.completeNode(nodeId) - } - commit("updateNode", { + try { + if (!wp.isLoggedIn()) { + const progressObj = JSON.parse(localStorage.getItem(LOCAL_PROGRESS_ID)) + const nodeProgress = progressObj[nodeId] || {} + nodeProgress.completed = true + localStorage.setItem(LOCAL_PROGRESS_ID, JSON.stringify(progressObj)) + } else { + await client.completeNode(nodeId) + } + commit("updateNode", { + id: nodeId, + newNode: { completed: true }, + }) + + const node = getters.getNode(nodeId) + if (node.mediaType !== "video") { + await dispatch("updateNodeProgress", { id: nodeId, - newNode: { completed: true }, + progress: 1, }) - - if (node.mediaType !== "video") { - await dispatch("updateNodeProgress", { - id: nodeId, - progress: 1, - }) - } - return unlockNodes(context) - } catch (error) { - dispatch("addApiError", error) } + return unlockNodes(context) + } catch (error) { + dispatch("addApiError", error) } } @@ -240,17 +234,14 @@ export async function getTapestryExport({ dispatch }) { } export async function completeQuestion( - { commit, getters, dispatch }, + { commit, dispatch }, { nodeId, questionId, answerType, answer } ) { - const node = getters.getNode(nodeId) - if (!Helpers.nodeAndUserAreDyad(node)) { - try { - await client.completeQuestion(nodeId, questionId, answerType, answer) - commit("completeQuestion", { nodeId, questionId, answerType, answer }) - } catch (error) { - dispatch("addApiError", error) - } + try { + await client.completeQuestion(nodeId, questionId, answerType, answer) + commit("completeQuestion", { nodeId, questionId, answerType, answer }) + } catch (error) { + dispatch("addApiError", error) } } diff --git a/templates/vue/src/store/mutations.js b/templates/vue/src/store/mutations.js index 78bc64904..70d6abe2e 100644 --- a/templates/vue/src/store/mutations.js +++ b/templates/vue/src/store/mutations.js @@ -1,6 +1,5 @@ import Vue from "vue" import * as getters from "./getters" -import Helpers from "@/utils/Helpers" import { parse } from "@/utils/dataset" export function init(state, { dataset, progress = {} }) { @@ -62,11 +61,9 @@ export function updateNode(state, payload) { export function updateNodeProgress(state, payload) { const node = getters.getNode(state)(payload.id) - if (!Helpers.nodeAndUserAreDyad(node)) { - state.nodes[payload.id] = { - ...node, - progress: payload.progress, - } + state.nodes[payload.id] = { + ...node, + progress: payload.progress, } } diff --git a/templates/vue/src/utils/Helpers.js b/templates/vue/src/utils/Helpers.js index 5bd335716..f31819356 100644 --- a/templates/vue/src/utils/Helpers.js +++ b/templates/vue/src/utils/Helpers.js @@ -389,16 +389,10 @@ export default class Helpers { unlocked: true, accessible: true, reviewComments: [], - isDyad: false, popup: null, } return Helpers.deepMerge(baseNode, overrides) } - - static nodeAndUserAreDyad(node) { - let roles = wp.getCurrentUser().roles - return !node.isDyad ? false : roles.includes("dyad") - } /** * Positions the tooltip to the given target. *