Changeset 35950


Ignore:
Timestamp:
2022-01-11T10:48:54+13:00 (2 years ago)
Author:
cstephen
Message:

Fix localStorage-backed properties

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/macron-restoration/src/components/DirectInput.vue

    r35902 r35950  
    1414            macroniseWaitTimeout: null,
    1515            waitingToMacronise: false,
    16             errorState: false
     16            errorState: false,
     17            preserveExistingMacrons: true,
     18            enableSpellcheck: false,
     19            showMacronisedWords: true,
     20            normaliseLinebreaks: false
    1721        }
    1822    },
    1923    computed: {
    20         preserveExistingMacrons: {
    21             get() {
    22                 const value = localStorage.getItem("preserveExistingMacrons");
    23                 return value ?? true;
    24             },
    25             set(newValue) {
    26                 localStorage.setItem("preserveExistingMacrons", newValue);
    27             }
    28         },
    29         enableSpellcheck: {
    30             get() {
    31                 return localStorage.getItem("enableSpellcheck");
    32             },
    33             set(newValue) {
    34                 localStorage.setItem("enableSpellcheck", newValue);
    35             }
    36         },
    37         showMacronisedWords: {
    38             get() {
    39                 const value = localStorage.getItem("showMacronisedWords");
    40                 return value ?? true;
    41             },
    42             set(newValue) {
    43                 localStorage.setItem("showMacronisedWords", newValue);
    44             }
    45         },
    46         normaliseLinebreaks: {
    47             get() {
    48                 return localStorage.getItem("normaliseLinebreaks");
    49             },
    50             set(newValue) {
    51                 localStorage.setItem("normaliseLinebreaks", newValue);
    52             }
    53         },
    5424        canDownload() {
    5525            return this.restored.length > 0 && !this.waitingToMacronise;
     
    11888            translations: state => state.translations
    11989        })
     90    },
     91    watch: {
     92        preserveExistingMacrons(newValue) {
     93            localStorage.setItem("preserveExistingMacrons", newValue);
     94        },
     95        enableSpellcheck(newValue) {
     96            localStorage.setItem("enableSpellcheck", newValue);
     97        },
     98        showMacronisedWords(newValue) {
     99            localStorage.setItem("showMacronisedWords", newValue);
     100        },
     101        normaliseLinebreaks(newValue) {
     102            localStorage.setItem("normaliseLinebreaks", newValue);
     103        }
    120104    },
    121105    methods: {
     
    184168            return result;
    185169        }
     170    },
     171    beforeMount() {
     172        // The null check is used to default this setting to true
     173        this.preserveExistingMacrons = (localStorage.getItem("preserveExistingMacrons") ?? "true") === "true";
     174        this.enableSpellcheck = localStorage.getItem("enableSpellcheck") === "true";
     175        this.showMacronisedWords = (localStorage.getItem("showMacronisedWords") ?? "true") === "true";
     176        this.normaliseLinebreaks = localStorage.getItem("normaliseLinebreaks") === "true";
    186177    }
    187178}
Note: See TracChangeset for help on using the changeset viewer.