Skip to content
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

Add your farms table reload on farm create #3515

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,21 @@ export default {
required: true,
},
},
setup(props) {

setup(props, context) {
const showDialogue = ref(false);
const isCreating = ref(false);
const gridStore = useGrid();
const valid = ref(false);

async function createFarm() {
try {
isCreating.value = true;
await gridStore.grid.farms.create({ name: props.name });
createCustomToast("Farm created successfully.", ToastType.success);
notifyDelaying();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you remove it? i think it will be better to notify the user that it will reload in a while

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added back

showDialogue.value = false;
context.emit("farm-created");
notifyDelaying();
} catch (error) {
console.log(error);
createCustomToast("Failed to create farm.", ToastType.danger);
Expand Down
21 changes: 19 additions & 2 deletions packages/playground/src/dashboard/components/user_farms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ import { type Farm, SortBy, SortOrder } from "@threefold/gridproxy_client";
import { jsPDF } from "jspdf";
import { debounce } from "lodash";
import { StrKey } from "stellar-sdk";
import { ref } from "vue";
import { ref, watch } from "vue";

import { gridProxyClient } from "@/clients";
import CardDetails from "@/components/node_details_cards/card_details.vue";
Expand All @@ -164,11 +164,26 @@ export default {
CardDetails,
AddIP,
},
setup(_, context) {
props: {
reloadFarms: {
type: Boolean,
},
},

setup(props, context) {
const gridStore = useGrid();
const profile = useProfileManager().profile;
const twinId = profile!.twinId;
const search = ref<string>();
watch(
() => props.reloadFarms,
async () => {
setTimeout(async () => {
await getUserFarms();
}, 30000);
},
);

const headers = [
{
title: "Farm ID",
Expand Down Expand Up @@ -213,6 +228,7 @@ export default {

const reloadFarms = debounce(getUserFarms, 20000);
async function getUserFarms() {
loading.value = true;
try {
const { data, count } = await gridProxyClient.farms.list({
retCount: true,
Expand Down Expand Up @@ -333,6 +349,7 @@ export default {
}

context.expose({ getFarmsNames, reloadFarms });

return {
gridStore,
headers,
Expand Down
6 changes: 4 additions & 2 deletions packages/playground/src/dashboard/farms_view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<v-card-title class="pa-0">Farms</v-card-title>
</v-card>

<CreateFarm v-model:name="name" class="mt-4" />
<UserFarms ref="userFarms" />
<CreateFarm v-model:name="name" class="mt-4" @farm-created="farmsReload = true" />
<UserFarms ref="userFarms" :reloadFarms="farmsReload" />
<UserNodes />
</div>
</template>
Expand All @@ -27,9 +27,11 @@ export default {
},
setup() {
const name = ref<string>("");
const farmsReload = ref<boolean>(false);

return {
name,
farmsReload,
};
},
};
Expand Down
Loading