Skip to content

Commit

Permalink
feat: persist workflows and logs sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed Nov 27, 2021
1 parent 0cf8903 commit fcd2db9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/newtab/pages/Workflows.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</div>
</template>
<script setup>
import { computed, shallowReactive } from 'vue';
import { computed, shallowReactive, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useDialog } from '@/composable/dialog';
import { sendMessage } from '@/utils/message';
Expand All @@ -76,10 +76,11 @@ const menu = [
{ id: 'delete', name: t('common.delete'), icon: 'riDeleteBin7Line' },
];
const savedSorts = JSON.parse(localStorage.getItem('workflow-sorts') || '{}');
const state = shallowReactive({
query: '',
sortBy: 'createdAt',
sortOrder: 'desc',
sortBy: savedSorts.sortBy || 'createdAt',
sortOrder: savedSorts.sortOrder || 'desc',
});
const workflows = computed(() =>
Expand Down Expand Up @@ -141,6 +142,16 @@ const menuHandlers = {
rename: renameWorkflow,
delete: deleteWorkflow,
};
watch(
() => [state.sortOrder, state.sortBy],
([sortOrder, sortBy]) => {
localStorage.setItem(
'workflow-sorts',
JSON.stringify({ sortOrder, sortBy })
);
}
);
</script>
<style>
.workflow-sort select {
Expand Down
16 changes: 13 additions & 3 deletions src/newtab/pages/logs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</div>
</template>
<script setup>
import { shallowReactive, ref, computed } from 'vue';
import { shallowReactive, ref, computed, watch } from 'vue';
import { useStore } from 'vuex';
import { useI18n } from 'vue-i18n';
import { useDialog } from '@/composable/dialog';
Expand All @@ -96,6 +96,8 @@ const { t } = useI18n();
const store = useStore();
const dialog = useDialog();
const savedSorts = JSON.parse(localStorage.getItem('logs-sorts') || '{}');
const selectedLogs = ref([]);
const pagination = shallowReactive({
perPage: 10,
Expand All @@ -107,8 +109,8 @@ const filtersBuilder = shallowReactive({
byStatus: 'all',
});
const sortsBuilder = shallowReactive({
order: 'desc',
by: 'startedAt',
order: savedSorts.order || 'desc',
by: savedSorts.by || 'startedAt',
});
const exportDataModal = shallowReactive({
show: false,
Expand Down Expand Up @@ -186,6 +188,14 @@ function selectAllLogs() {
selectedLogs.value = logIds;
}
watch(
() => sortsBuilder,
(value) => {
localStorage.setItem('logs-sorts', JSON.stringify(value));
},
{ deep: true }
);
</script>
<style>
.logs-list-data {
Expand Down

0 comments on commit fcd2db9

Please sign in to comment.