-
Notifications
You must be signed in to change notification settings - Fork 633
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add '@vue/composition-api' plugin; refactor SelectAddressForm with setup()
; implement #7345
#8118
Merged
jonboiser
merged 14 commits into
learningequality:develop
from
jonboiser:save-net-addresses
Jun 7, 2021
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f16e020
Add @vue/composition-api
jonboiser 0dad167
Add vueuse
jonboiser 55ae531
Add eslint rule for Vue.setup location
jonboiser 211201d
Move peer discovery code to usable
jonboiser 2f10070
Add no-shadow eslint rule
jonboiser 038b44c
Move saved addresses code to usable
jonboiser bdeb713
Refactor before fixing the resetSelectedAddress bug
jonboiser 7444c7e
Don't reset this.selectedAddress if user has chosen one previously
jonboiser f92c647
addresses -> combinedAddresses
jonboiser a45a598
Save last selected address in localStorage
jonboiser b415b12
Revert "Add no-shadow eslint rule"
jonboiser a5d6ad5
Use vueuse 'get' and 'set' utilities to remove use of .value
jonboiser 2ddc192
Refactor useDynamicAddresses to use vueuse utilities
jonboiser b53573f
Upgrade vue-composition-api to 1.0.0-rc.11
jonboiser File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
75 changes: 75 additions & 0 deletions
75
kolibri/core/assets/src/views/sync/SelectAddressModalGroup/useDynamicAddresses.js
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,75 @@ | ||
import { | ||
ref, | ||
computed, | ||
onBeforeMount, | ||
onBeforeUnmount, | ||
getCurrentInstance, | ||
} from '@vue/composition-api'; | ||
import { fetchDynamicAddresses } from './api'; | ||
|
||
const Stages = Object.freeze({ | ||
PEER_DISCOVERY_STARTED: 'PEER_DISCOVERY_STARTED', | ||
PEER_DISCOVERY_SUCCESSFUL: 'PEER_DISCOVERY_SUCCESSFUL', | ||
PEER_DISCOVERY_FAILED: 'PEER_DISCOVERY_FAILED', | ||
}); | ||
|
||
export default function useDynamicAddresses(props) { | ||
const { fetchAddressArgs, discoverySpinnerTime } = props; | ||
const addresses = ref([]); | ||
const stage = ref(''); | ||
const intervalId = ref(''); | ||
const discoveredAddressesInitiallyFetched = ref(false); | ||
const $parent = getCurrentInstance().proxy.$parent; | ||
|
||
function parentEmit(event, ...args) { | ||
$parent.$emit(event, ...args); | ||
} | ||
|
||
function discoverPeers() { | ||
parentEmit('started_peer_discovery'); | ||
stage.value = Stages.PEER_DISCOVERY_STARTED; | ||
return fetchDynamicAddresses(fetchAddressArgs) | ||
.then(devices => { | ||
addresses.value = devices; | ||
parentEmit('finished_peer_discovery'); | ||
setTimeout(() => { | ||
stage.value = Stages.PEER_DISCOVERY_SUCCESSFUL; | ||
}, discoverySpinnerTime); | ||
discoveredAddressesInitiallyFetched.value = true; | ||
}) | ||
.catch(() => { | ||
parentEmit('peer_discovery_failed'); | ||
stage.value = Stages.PEER_DISCOVERY_FAILED; | ||
}); | ||
} | ||
|
||
// Start polling | ||
onBeforeMount(() => { | ||
discoverPeers(); | ||
if (!intervalId.value) { | ||
intervalId.value = setInterval(discoverPeers, 5000); | ||
} | ||
}); | ||
|
||
// Stop polling | ||
onBeforeUnmount(() => { | ||
if (intervalId.value) { | ||
intervalId.value = clearInterval(intervalId.value); | ||
} | ||
}); | ||
|
||
const discoveringPeers = computed(() => { | ||
return stage.value === Stages.PEER_DISCOVERY_STARTED; | ||
}); | ||
|
||
const discoveryFailed = computed(() => { | ||
return stage.value === Stages.PEER_DISCOVERY_FAILED; | ||
}); | ||
|
||
return { | ||
addresses, | ||
discoveringPeers, | ||
discoveryFailed, | ||
discoveredAddressesInitiallyFetched, | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! you learn something new every day, and today I learned about this