Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
matmon12 committed Oct 16, 2024
1 parent f22c715 commit 118e947
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 47 deletions.
42 changes: 24 additions & 18 deletions src/components/dashboard/PostDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<script setup>
import { ref, defineProps, defineModel, watch } from "vue";
import { getClasses } from "@/utils/classes";
import { areArraysEqual, uppercaseFirst } from "@/utils/index";
import { areArraysEqual, uppercaseFirst, translitForUrl } from "@/utils/index";
import {
deleteImage,
uploadImage,
Expand Down Expand Up @@ -297,24 +297,29 @@ const saveEditedPost = async () => {
let success = false;
let updatedPost = {};
props.post.name !== values.name ? (updatedPost.name = values.name) : null;
props.post.description !== description.value
? (updatedPost.description = description.value)
: null;
props.post.image !== values.image ? (updatedPost.image = values.image) : null;
props.post.category !== values.category
? (updatedPost.category = values.category)
: null;
if (props.post.name !== values.name) {
updatedPost.name = values.name;
updatedPost.slug = translitForUrl(values.name);
}
if(props.post.description !== description.value) {
updatedPost.description = description.value
}
if(props.post.category !== values.category) {
updatedPost.category = values.category
}
if(props.post.description !== description.value) {
updatedPost.time = getTimeReading()
}
if(props.post.summary !== values.summary) {
updatedPost.summary = values.summary
}
if(!areArraysEqual(props.post.tags, values.tags)) {
updatedPost.tags = values.tags
}
if(props.post.image !== values.image) {
updatedPost.image = values.image
}
updatedPost.date = new Date().getTime();
props.post.description !== description.value
? (updatedPost.time = getTimeReading())
: null;
props.post.summary !== values.summary
? (updatedPost.summary = values.summary)
: null;
!areArraysEqual(props.post.tags, values.tags)
? (updatedPost.tags = values.tags)
: null;
try {
if (file.value) {
Expand Down Expand Up @@ -374,6 +379,7 @@ const saveNewPost = async () => {
const newPost = {
id: id,
name: values.name,
slug: translitForUrl(values.name),
description: description.value,
summary: values.summary,
image: values.image,
Expand Down
5 changes: 2 additions & 3 deletions src/pages/CategoryNews.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import {
} from "firebase/firestore";
import { postsRef } from "@/server/firebase.config";
import { readToDB } from "@/server/index";
import { onToBack, translitForUrl } from "../utils/index";
import { onToBack } from "../utils/index";
import { useRoute } from "vue-router";
import router from "../router/router";
Expand Down Expand Up @@ -181,12 +181,11 @@ const generateSequence = (count) => {
};
const navigateToPost = (post) => {
localStorage.setItem("post", JSON.stringify({ id: post.id }));
router.push({
name: "Post",
params: {
category: post.category,
name: translitForUrl(post.name),
name: post.slug,
},
});
};
Expand Down
17 changes: 6 additions & 11 deletions src/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ref, onMounted, watch } from "vue";
import { useSearchStore } from "@/stores/search";
import { useForecastStore } from "@/stores/forecast";
import axiosApiInstance from "@/api";
import { CURRENT_URL, ASTRO_URL, HISTORY_URL } from "@/constants/index";
import { CURRENT_URL, ASTRO_URL, FORECAST_URL } from "../constants/index";
const searchStore = useSearchStore();
const forecastStore = useForecastStore();
Expand All @@ -38,7 +38,7 @@ watch(
(newValue) => {
if (newValue) {
getWeatherData().then(() => {
getHistoryDay();
getMinMax();
});
fetchAstroData();
}
Expand Down Expand Up @@ -79,16 +79,11 @@ const fetchAstroData = async () => {
});
};
const getHistoryDay = async () => {
const date = new Date().toLocaleDateString("en-GB", {
timeZone: searchStore.curWeather.location.tz_id,
});
const formattedDate = `${date.split("/")[2]}-${date.split("/")[1]}-${
date.split("/")[0]
}`;
const getMinMax = async () => {
await axiosApiInstance
.get(`${HISTORY_URL}?q=${searchStore.search}&dt=${formattedDate}`)
.get(`${FORECAST_URL}?q=${searchStore.search}&days=1`)
.then((res) => {
console.log(res)
searchStore.maxTemp = res.data.forecast.forecastday[0].day.maxtemp_c;
searchStore.minTemp = res.data.forecast.forecastday[0].day.mintemp_c;
})
Expand All @@ -105,7 +100,7 @@ onMounted(() => {
searchStore.error !== 1006
) {
getWeatherData().then(() => {
getHistoryDay();
getMinMax();
});
fetchAstroData();
}
Expand Down
27 changes: 12 additions & 15 deletions src/pages/Post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
<div class="post-block post__share">
<h4 class="post__share-title">Поделитесь новостью</h4>
<div class="post-links">
<a
v-for="(link, index) of links"
:key="index"
:href="link.link"
>
<a v-for="(link, index) of links" :key="index" :href="link.link">
<component :is="link.icon"></component>
</a>
</div>
Expand All @@ -43,34 +39,35 @@
<script setup>
import { useRoute } from "vue-router";
import { ref, markRaw, defineProps, onMounted, onUnmounted } from "vue";
import { getDocFromDB } from "@/server/index";
import { readToDB } from "@/server/index";
import { query, where } from "firebase/firestore";
import { postsRef } from "@/server/firebase.config";
import AkarIconsVkFill from "~icons/akar-icons/vk-fill";
const postId = ref();
const post = ref();
const loadingPost = ref(false);
const errorPost = ref();
const route = useRoute();
const links = markRaw([
{ icon: AkarIconsVkFill, link: `https://vk.com/share.php?url=${window.location.href}` },
{
icon: AkarIconsVkFill,
link: `https://vk.com/share.php?url=${window.location.href}`,
},
]);
onMounted(() => {
postId.value = getIdPost();
getPost();
});
const getIdPost = () => {
const post = JSON.parse(localStorage.getItem("post"));
return post.id;
};
const getPost = async () => {
loadingPost.value = true;
errorPost.value = null;
try {
post.value = await getDocFromDB(postId.value);
const querySnapshot = await readToDB(
query(postsRef, where("slug", "==", route.params.name))
);
post.value = querySnapshot.docs[0].data();
} catch (error) {
const stringToObject = JSON.parse(error.message);
errorPost.value = stringToObject;
Expand Down

0 comments on commit 118e947

Please sign in to comment.