Skip to content

Commit

Permalink
Merge branch 'next' of github.com:traderfour/trader4.net into next
Browse files Browse the repository at this point in the history
  • Loading branch information
t4-muhammad committed Jun 6, 2023
2 parents 8643ddb + af7eb8e commit c44ee06
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
31 changes: 8 additions & 23 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</button>

<li
v-for="(tag, index) in tags"
v-for="(tag, index) in categories"
:key="index"
class="px-3 py-1 min-w-fit rounded my-auto bg-white text-gray-600 cursor-pointer dark:bg-gray-800 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 transition duration-300 ease-in-out transform"
>
Expand Down Expand Up @@ -104,30 +104,15 @@
</div>
</template>
<script lang="ts" setup>
const tags = ref<ICategory[]>();
const loading = ref(true);
const posts = ref();
onMounted(() => {
loading.value = true;
store
.getPosts()
.then((res: any) => {
loading.value = false;
posts.value = res.data.results;
})
.catch((err) => {
loading.value = false;
});
});
const { data }: { data: any } = await useApi("/v1/categories");
if (data) {
tags.value = data.results as ICategory[];
}
const tagBox = ref<Ref | null>(null);
const {
categories,
fetchCategories,
}: { categories: Ref<ICategory[]>; fetchCategories: any } = useMarketStore();
fetchCategories();
const store = usePostsStore();
const { getPosts, posts, loading } = usePostsStore();
getPosts("/v1/posts");
const { locale } = useI18n();
const rtlLangList = [
Expand Down
10 changes: 4 additions & 6 deletions store/my.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const useMyStore = () => {
const { $toast } = useNuxtApp();
const list = ref<IPosts>();
const loading = ref<boolean>(false);
const list = ref();
const loading = ref(true);

const createItem = async (route: string, payload: any) => {
return await useApi(route, {
Expand All @@ -12,17 +12,15 @@ export const useMyStore = () => {
});
};

const getList = async (route: string) => {
loading.value = true;
await useApi(route)
const getList = (route: string) => {
useApi(route)
.then((res) => {
const response = res.data as IApiResponse;
loading.value = false;
list.value = response.results;
})
.catch((err) => {
loading.value = false;
console.log(err.data.message, "err");
$toast.error(err.data.message, { position: "top-right" });
});
};
Expand Down
16 changes: 13 additions & 3 deletions store/posts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const usePostsStore = () => {
const { $toast } = useNuxtApp();
const loading = ref(true);
const posts = ref([]);
const posts = ref<IPosts[]>([]);
let post = ref<IPosts>({} as IPosts);
const metas = ref({});

Expand All @@ -22,8 +23,17 @@ export const usePostsStore = () => {
});
};

const getPosts = async () => {
return await useApi("/v1/posts");
const getPosts = (route: string) => {
useApi(route)
.then((res) => {
const response = res.data as IApiResponse;
loading.value = false;
posts.value = response.results;
})
.catch((err) => {
loading.value = false;
$toast.error(err.data.message, { position: "top-right" });
});
};

const getPost = async (slogan: string) => {
Expand Down

0 comments on commit c44ee06

Please sign in to comment.