|
| 1 | +<script setup> |
| 2 | +import axios from 'axios'; |
| 3 | +import { onMounted, ref } from 'vue'; |
| 4 | +
|
| 5 | +import Navigation from '../../components/Navigation.vue'; |
| 6 | +
|
| 7 | +const language = ref('en'); |
| 8 | +const theme = ref('light'); |
| 9 | +
|
| 10 | +const retrieve = () => { |
| 11 | + axios |
| 12 | + .get('/api/settings', { headers: { 'api-key': localStorage.getItem('api_key') } }) |
| 13 | + .then(response => { |
| 14 | + language.value = response.data.language; |
| 15 | + theme.value = response.data.theme; |
| 16 | + }); |
| 17 | +}; |
| 18 | +
|
| 19 | +const update = () => { |
| 20 | + axios |
| 21 | + .post('/api/settings', { language: language.value, theme: theme.value }, { headers: { 'api-key': localStorage.getItem('api_key') } }) |
| 22 | + .then(() => { |
| 23 | + // Done |
| 24 | + }) |
| 25 | + .catch(() => { |
| 26 | + alert('Unable to save'); |
| 27 | + }); |
| 28 | +}; |
| 29 | +
|
| 30 | +onMounted(() => retrieve()); |
| 31 | +</script> |
| 32 | + |
| 33 | +<template> |
| 34 | + <div> |
| 35 | + <Navigation /> |
| 36 | + <div class="my-10 mx-auto max-w-3xl"> |
| 37 | + <div class="p-5 bg-white border border-gray-200 rounded-lg"> |
| 38 | + <div class="space-y-5 max-w-xs"> |
| 39 | + <div> |
| 40 | + <div class="mb-2 text-sm">Language</div> |
| 41 | + <select class="px-3.5 py-2.5 w-full text-sm border border-gray-200 rounded-lg appearance-none" v-model="language" @change="update"> |
| 42 | + <option value="en">English</option> |
| 43 | + <option value="nl">Dutch</option> |
| 44 | + <option value="dk">Danish</option> |
| 45 | + <option value="de">German</option> |
| 46 | + <option value="fr">French</option> |
| 47 | + <option value="pt">Portuguese</option> |
| 48 | + <option value="ru">Russian</option> |
| 49 | + </select> |
| 50 | + </div> |
| 51 | + <div> |
| 52 | + <div class="mb-2 text-sm">Theme</div> |
| 53 | + <select class="px-3.5 py-2.5 w-full text-sm border border-gray-200 rounded-lg appearance-none" v-model="theme" @change="update"> |
| 54 | + <option value="light">Light</option> |
| 55 | + <option value="dark">Dark</option> |
| 56 | + </select> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | +</template> |
0 commit comments