manifest/nuxt/components/Pojem.vue

140 lines
2.8 KiB
Vue
Raw Normal View History

<script setup="setup">
2023-11-13 00:22:34 +01:00
import { stripHtml } from 'string-strip-html'
const { etherFetch } = useEtherpadApi()
const { poskrolaj } = useUi()
const store = usePojmiStore()
2024-04-01 19:59:09 +02:00
const nastavitveStore = useNastavitveStore()
const route = useRoute()
const { izbraniJezik } = storeToRefs(nastavitveStore)
2024-07-24 14:38:45 +02:00
const routeName = computed(() => route.name)
const props = defineProps({
pojemid: String
})
if (props.pojemid && !(props.pojemid in store.pojmi)) {
await store.naloziPojme(izbraniJezik.value)
}
2024-04-01 19:59:09 +02:00
watch(izbraniJezik, jezik => {
2024-07-24 14:38:45 +02:00
console.log('PONOVNO NALAGAM POJME!', jezik)
2024-04-01 19:59:09 +02:00
store.naloziPojme(jezik)
})
const pojem = computed(() => store.pojmi[props.pojemid])
2024-01-24 18:54:28 +01:00
const revisionId = computed(() => pojem.value ? pojem.value.id : null)
2023-11-13 00:22:34 +01:00
const urejanje = ref(false)
const container = ref(null)
2024-01-24 17:37:41 +01:00
const obrazec = ref(null)
2023-11-13 00:22:34 +01:00
const urediPojem = async () => {
// Ustvari pad s tekstom pojma, ce se ne obstaja
const tekstPojma = stripHtml(pojem.value.tekst).result
const resp = await etherFetch('/createPad', {
2024-07-24 14:38:45 +02:00
padID: izbraniJezik.value + '-' + revisionId.value,
text: tekstPojma
})
2023-11-13 00:22:34 +01:00
urejanje.value = true
}
onMounted(() => {
2024-01-24 18:54:28 +01:00
// Prazen pojem? Nazaj na manifest
if ((!pojem.value || !pojem.value.id) && store.pojmi) {
navigateTo(localePath('manifest') + '#skrol')
2024-01-24 18:54:28 +01:00
}
2024-07-24 14:38:45 +02:00
// Poskrolaj na pojem
poskrolaj(container.value.parentNode)
// Link na editiranje pojma? odpri editiranje
if (routeName.value.startsWith('pojem_uredi')) {
urediPojem()
}
})
onUpdated(() => {
if (route.params.guid === revisionId.value) {
poskrolaj(obrazec.value)
}
})
</script>
<template>
<section ref="container">
2024-04-01 21:23:23 +02:00
<div v-if="!urejanje" class="gumb" @click="urediPojem">{{ $t('Uredi')}}</div>
<div v-if="pojem" class="pojem">
<h2>
{{ pojem.naslov }}
2024-06-14 13:45:13 +02:00
<StrojniPrevod v-if="pojem.strojni_prevod" />
</h2>
<div class="tekst" v-html="pojem.tekst" />
2023-11-13 00:22:34 +01:00
</div>
<div class="obrazec" ref="obrazec">
<PojemForm v-if="urejanje"
ref="obrazec"
:revisionId="revisionId"
:pojem="pojem"
2024-07-24 14:38:45 +02:00
:onZapri="() => navigateTo(localePath({ name: 'pojem_poglej', params: { pojemid: revisionId }}))" />
</div>
</section>
</template>
<style scoped>
2024-01-24 17:37:41 +01:00
section {
width: 100%;
}
.pojem {
2024-01-07 22:33:20 +01:00
position: relative;
width: 50%;
float: left;
2024-01-07 22:33:20 +01:00
}
h2 {
text-transform: uppercase;
margin-top: 0;
}
form.pojem {
width: 100%;
}
.obrazec {
width: calc(50% - 32px);
margin-left: 32px;
float: right;
}
2024-01-07 22:33:20 +01:00
.gumb {
position: sticky;
top: 0;
2024-01-07 22:33:20 +01:00
right: 0;
float: right;
2024-01-07 22:33:20 +01:00
}
@media screen and (max-width: 768px) {
.pojem {
2024-01-07 22:33:20 +01:00
min-height: 4rem;
width: 100%;
}
2024-01-19 12:42:02 +01:00
.obrazec {
width: 100%;
margin-left: 0;
}
form.pojem {
min-height: 70vh;
width: 100%;
margin-left: 0;
2024-01-07 22:33:20 +01:00
}
2024-01-06 18:48:22 +01:00
}
</style>