2020-03-12 14:29:21 +01:00
< template >
2020-02-18 08:57:00 +01:00
< div >
2020-06-25 11:36:35 +02:00
< nav class = "breadcrumb" aria -label = " breadcrumbs " >
< ul >
< li >
2020-11-30 10:24:11 +01:00
< router -link : to = "{ name: RouteName.ACCOUNT_SETTINGS }" > { {
$t ( "Account" )
} } < / r o u t e r - l i n k >
2020-06-25 11:36:35 +02:00
< / li >
< li class = "is-active" >
2020-11-30 10:24:11 +01:00
< router -link : to = "{ name: RouteName.PREFERENCES }" > { {
$t ( "Preferences" )
} } < / r o u t e r - l i n k >
2020-06-25 11:36:35 +02:00
< / li >
< / ul >
< / nav >
< div >
< b -field :label ="$t('Language')" >
< b -select
: loading = "!config || !loggedUser"
2020-10-28 18:58:43 +01:00
v - model = "locale"
2020-06-25 11:36:35 +02:00
: placeholder = "$t('Select a language')"
>
2020-10-13 20:39:59 +02:00
< option v-for ="(language, lang) in langs" :value="lang" :key ="lang" >
2020-06-25 11:36:35 +02:00
{ { language } }
2020-02-18 08:57:00 +01:00
< / option >
2020-06-25 11:36:35 +02:00
< / b - s e l e c t >
< / b - f i e l d >
2021-02-12 18:19:49 +01:00
< b -field :label ="$t('Timezone')" v-if ="selectedTimezone" >
2020-06-25 11:36:35 +02:00
< b -select
: placeholder = "$t('Select a timezone')"
: loading = "!config || !loggedUser"
v - model = "selectedTimezone"
>
2020-11-30 10:24:11 +01:00
< optgroup
: label = "group"
v - for = "(groupTimezones, group) in timezones"
: key = "group"
>
2020-06-25 11:36:35 +02:00
< option
v - for = "timezone in groupTimezones"
: value = "`${group}/${timezone}`"
: key = "timezone"
>
{ { sanitize ( timezone ) } }
< / option >
< / optgroup >
< / b - s e l e c t >
< / b - f i e l d >
2020-10-21 09:04:29 +02:00
< em v-if ="Intl.DateTimeFormat().resolvedOptions().timeZone" > {{
2020-06-25 11:36:35 +02:00
$t ( "Timezone detected as {timezone}." , {
timezone : Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ,
} )
} } < / em >
2020-11-30 10:24:11 +01:00
< b -message v -else type = "is-danger" > { {
$t ( "Unable to detect timezone." )
} } < / b - m e s s a g e >
2021-02-12 18:19:49 +01:00
< hr / >
< b -field grouped >
< b -field : label = "$t('City or region')" expanded >
< address -auto -complete
2021-03-16 18:51:34 +01:00
v - if = "loggedUser && loggedUser.settings"
2021-02-12 18:19:49 +01:00
: type = "AddressSearchType.ADMINISTRATIVE"
2021-03-02 10:02:06 +01:00
: doGeoLocation = "false"
2021-02-12 18:19:49 +01:00
v - model = "address"
>
< / a d d r e s s - a u t o - c o m p l e t e >
< / b - f i e l d >
< b -field :label ="$t('Radius')" >
< b -select
: placeholder = "$t('Select a radius')"
v - model = "locationRange"
>
< option
v - for = "index in [1, 5, 10, 25, 50, 100]"
: key = "index"
: value = "index"
>
{ { $tc ( "{count} km" , index , { count : index } ) } }
< / option >
< / b - s e l e c t >
< / b - f i e l d >
2021-04-16 17:18:41 +02:00
< b -button
: disabled = "address == undefined"
@ click = "resetArea"
class = "reset-area"
icon - left = "close"
/ >
2021-02-12 18:19:49 +01:00
< / b - f i e l d >
< p >
{ {
$t (
2021-03-04 15:26:03 +01:00
"Your city or region and the radius will only be used to suggest you events nearby. The event radius will consider the administrative center of the area."
2021-02-12 18:19:49 +01:00
)
} }
< / p >
2020-06-25 11:36:35 +02:00
< / div >
2020-02-18 08:57:00 +01:00
< / div >
2020-03-12 14:29:21 +01:00
< / template >
< script lang = "ts" >
2021-03-04 15:26:30 +01:00
import { Component , Vue } from "vue-property-decorator" ;
2021-02-12 18:19:49 +01:00
import ngeohash from "ngeohash" ;
2020-10-28 18:58:43 +01:00
import { saveLocaleData } from "@/utils/auth" ;
2020-02-18 08:57:00 +01:00
import { TIMEZONES } from "../../graphql/config" ;
2020-11-30 10:24:11 +01:00
import {
USER _SETTINGS ,
SET _USER _SETTINGS ,
UPDATE _USER _LOCALE ,
} from "../../graphql/user" ;
2020-02-18 08:57:00 +01:00
import { IConfig } from "../../types/config.model" ;
2021-02-12 18:19:49 +01:00
import { IUser , IUserSettings } from "../../types/current-user.model" ;
2020-06-16 18:00:27 +02:00
import langs from "../../i18n/langs.json" ;
2020-06-25 11:36:35 +02:00
import RouteName from "../../router/name" ;
2021-02-12 18:19:49 +01:00
import AddressAutoComplete from "../../components/Event/AddressAutoComplete.vue" ;
import { AddressSearchType } from "@/types/enums" ;
import { Address , IAddress } from "@/types/address.model" ;
2020-03-12 14:29:21 +01:00
2020-02-18 08:57:00 +01:00
@ Component ( {
apollo : {
config : TIMEZONES ,
loggedUser : USER _SETTINGS ,
} ,
2021-02-12 18:19:49 +01:00
components : {
AddressAutoComplete ,
} ,
2021-05-25 16:21:29 +02:00
metaInfo ( ) {
return {
title : this . $t ( "Preferences" ) as string ,
} ;
} ,
2020-02-18 08:57:00 +01:00
} )
2020-03-12 14:29:21 +01:00
export default class Preferences extends Vue {
2020-02-18 08:57:00 +01:00
config ! : IConfig ;
2020-03-12 14:29:21 +01:00
2020-06-27 19:12:45 +02:00
loggedUser ! : IUser ;
2020-02-18 08:57:00 +01:00
2020-06-25 11:36:35 +02:00
RouteName = RouteName ;
2020-10-13 20:39:59 +02:00
langs : Record < string , string > = langs ;
2021-02-12 18:19:49 +01:00
AddressSearchType = AddressSearchType ;
2021-03-04 15:26:30 +01:00
get selectedTimezone ( ) : string {
if ( this . loggedUser ? . settings ? . timezone ) {
return this . loggedUser . settings . timezone ;
}
return Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
}
set selectedTimezone ( selectedTimezone : string ) {
if ( selectedTimezone !== this . loggedUser ? . settings ? . timezone ) {
this . updateUserSettings ( { timezone : selectedTimezone } ) ;
}
}
get locale ( ) : string {
if ( this . loggedUser ? . locale ) {
return this . loggedUser ? . locale ;
2020-02-18 08:57:00 +01:00
}
2021-03-04 15:26:30 +01:00
return this . $i18n . locale ;
}
set locale ( locale : string ) {
if ( locale ) {
this . $apollo . mutate ( {
mutation : UPDATE _USER _LOCALE ,
variables : {
locale ,
} ,
} ) ;
saveLocaleData ( locale ) ;
2020-06-16 18:00:27 +02:00
}
2020-02-18 08:57:00 +01:00
}
2020-10-13 20:39:59 +02:00
// eslint-disable-next-line class-methods-use-this
2020-02-18 08:57:00 +01:00
sanitize ( timezone : string ) : string {
2020-11-30 10:24:11 +01:00
return timezone
. split ( "_" )
. join ( " " )
. replace ( "St " , "St. " )
. split ( "/" )
. join ( " - " ) ;
2020-02-18 08:57:00 +01:00
}
2020-10-13 20:39:59 +02:00
get timezones ( ) : Record < string , string [ ] > {
2020-02-18 08:57:00 +01:00
if ( ! this . config || ! this . config . timezones ) return { } ;
2020-11-30 10:24:11 +01:00
return this . config . timezones . reduce (
( acc : { [ key : string ] : Array < string > } , val : string ) => {
const components = val . split ( "/" ) ;
const [ prefix , suffix ] = [
components . shift ( ) as string ,
components . join ( "/" ) ,
] ;
const pushOrCreate = (
acc2 : { [ key : string ] : Array < string > } ,
prefix2 : string ,
suffix2 : string
) => {
// eslint-disable-next-line no-param-reassign
( acc2 [ prefix2 ] = acc2 [ prefix2 ] || [ ] ) . push ( suffix2 ) ;
return acc2 ;
} ;
if ( suffix ) {
return pushOrCreate ( acc , prefix , suffix ) ;
}
return pushOrCreate ( acc , this . $t ( "Other" ) as string , prefix ) ;
} ,
{ }
) ;
2020-02-18 08:57:00 +01:00
}
2021-02-12 18:19:49 +01:00
get address ( ) : IAddress | null {
if (
this . loggedUser ? . settings ? . location ? . name &&
this . loggedUser ? . settings ? . location ? . geohash
) {
const { latitude , longitude } = ngeohash . decode (
this . loggedUser ? . settings ? . location ? . geohash
) ;
const name = this . loggedUser ? . settings ? . location ? . name ;
return {
description : name ,
locality : "" ,
type : "administrative" ,
geom : ` ${ longitude } ; ${ latitude } ` ,
street : "" ,
postalCode : "" ,
region : "" ,
country : "" ,
} ;
}
return null ;
}
set address ( address : IAddress | null ) {
if ( address && address . geom ) {
const { geom } = address ;
const addressObject = new Address ( address ) ;
const queryText = addressObject . poiInfos . name ;
const [ lon , lat ] = geom . split ( ";" ) ;
const geohash = ngeohash . encode ( lat , lon , 6 ) ;
if ( queryText && geom ) {
this . updateUserSettings ( {
location : {
geohash ,
name : queryText ,
} ,
} ) ;
}
}
}
2021-04-16 17:18:41 +02:00
get locationRange ( ) : number | undefined | null {
2021-02-12 18:19:49 +01:00
return this . loggedUser ? . settings ? . location ? . range ;
}
2021-04-16 17:18:41 +02:00
set locationRange ( locationRange : number | undefined | null ) {
2021-02-12 18:19:49 +01:00
if ( locationRange ) {
this . updateUserSettings ( {
location : {
range : locationRange ,
} ,
} ) ;
}
}
2021-04-16 17:18:41 +02:00
resetArea ( ) : void {
this . updateUserSettings ( {
location : {
geohash : null ,
name : null ,
range : null ,
} ,
} ) ;
}
2021-02-12 18:19:49 +01:00
private async updateUserSettings ( userSettings : IUserSettings ) {
await this . $apollo . mutate < { setUserSetting : string } > ( {
mutation : SET _USER _SETTINGS ,
variables : userSettings ,
2021-03-29 17:26:18 +02:00
refetchQueries : [ { query : USER _SETTINGS } ] ,
2021-02-12 18:19:49 +01:00
} ) ;
}
2020-03-12 14:29:21 +01:00
}
2020-02-18 08:57:00 +01:00
< / script >
2021-04-16 17:18:41 +02:00
< style lang = "scss" scoped >
. reset - area {
align - self : center ;
position : relative ;
top : 10 px ;
}
< / style >