Skip to content

Commit

Permalink
rootScope service, watch lang
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Oct 19, 2024
1 parent 3115b9c commit 9003d3f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
15 changes: 9 additions & 6 deletions app/scripts/components/CorpusUpdates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ref } from "vue"
import moment from "moment"
import settings from "@/settings"
import { loc, locObj } from "@/i18n"
import { rootScope } from "@/vue-services"
// type CorpusUpdatesScope = IScope & {
// LIMIT: number
Expand All @@ -13,12 +14,13 @@ import { loc, locObj } from "@/i18n"
// toggleExpanded: (to?: boolean) => void
// }
defineProps(["lang"])
const LIMIT = 5
let recentUpdates = ref()
let recentUpdatesFiltered = ref()
let expanded = ref(false)
const lang = ref(rootScope.lang)
const recentUpdates = ref()
const recentUpdatesFiltered = ref()
const expanded = ref(false)
rootScope.$watch("lang", (value) => (lang.value = value))
if (settings.frontpage?.corpus_updates) {
const limitDate = moment().subtract(6, "months")
Expand All @@ -42,7 +44,8 @@ function toggleExpanded(to) {
<article v-for="corpus in recentUpdatesFiltered">
<time :datetime="corpus.info.Updated" class="opacity-75 float-right">{{ corpus.info.Updated }}</time>
<div>
<strong>{{ locObj(corpus.title, lang) }}</strong> {{ loc("front_corpus_updated", lang) }}.
<strong>{{ locObj(corpus.title, lang) }}</strong>
{{ loc("front_corpus_updated", lang) }}.
</div>
</article>
<div v-if="recentUpdates.length > LIMIT">
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/components/frontpage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default angular.module("korpApp").component("frontpage", {
<search-examples ng-if="examples" class="w-80 grow"></search-examples>
</div>
<corpus-updates class="w-80 grow" v-props-lang="$root.lang"></corpus-updates>
<corpus-updates class="w-80 grow"></corpus-updates>
<newsdesk ng-if="newsdeskIsEnabled" class="w-80 grow"></newsdesk>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const fromKeys = <K extends keyof any, T>(keys: K[], getValue: (key: K) =
Object.fromEntries(keys.map((key) => [key, getValue(key)]))

/** Mapping from service names to their TS types. */
type ServiceTypes = {
export type ServiceTypes = {
$controller: IControllerService
$http: IHttpService
$location: LocationService
Expand Down
16 changes: 16 additions & 0 deletions app/scripts/vue-services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @format */

import angular, { type auto } from "angular"
import { RootScope } from "./root-scope.types"
import { ServiceTypes } from "./util"

export let rootScope: RootScope

angular.module("korpApp").run([
"$injector",
($injector: auto.IInjectorService) => {
// Enhance return type of $injector.get()
const getService: <K extends keyof ServiceTypes>(name: K) => ServiceTypes[K] = $injector.get
rootScope = getService("$rootScope")
},
])

0 comments on commit 9003d3f

Please sign in to comment.