Skip to content

Commit c30759b

Browse files
authored
select dark theme based on os preferences
1 parent 2da92ab commit c30759b

File tree

7 files changed

+95
-10
lines changed

7 files changed

+95
-10
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: build
22

3-
on: [push, pull_request]
3+
on: [pull_request]
44

55
jobs:
66
build:

TODO.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- [x] Priority
1515
- [x] Message text
16+
- [ ] Unit
1617
- [ ] Time range
1718

1819
## Quick filter bar
@@ -21,8 +22,8 @@
2122

2223
## Dark theme
2324

24-
- [ ] Add dark theme
25-
- [ ] Add auto-detection to select dark theme
25+
- [x] Add dark theme
26+
- [x] Add auto-detection to select dark theme
2627

2728
## Break down components
2829

@@ -36,12 +37,12 @@
3637

3738
- [x] Published in <https://aur.archlinux.org/packages/journal-viewer-bin>
3839

39-
## Automate reelase process
40+
## Automate relase process
4041

4142
- [x] Document build & publish process
4243
- [ ] Automate process
4344

44-
## Invesitgate possibility of flatpak
45+
## Investigate possibility of flatpak
4546

4647
## Bugs
4748

src/App.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let vm = reactive({
1313
isSidebarCollapsed: true,
1414
priority: "6",
1515
quickSearch: "",
16+
theme: "",
1617
});
1718
1819
let journalQuery = {
@@ -85,13 +86,20 @@ function filter(filter: Filter) {
8586
}
8687
8788
onMounted(() => {
89+
const match = window.matchMedia("(prefers-color-scheme: dark)");
90+
91+
if (match) {
92+
vm.theme = "dark";
93+
document.getElementsByTagName("html")[0].style = "background-color: #222;";
94+
}
95+
8896
getLogs();
8997
});
9098
</script>
9199

92100
<template>
93101
<header></header>
94-
<main>
102+
<main :class="vm.theme">
95103
<SummaryBar />
96104
<SearchBar @quick-search="quickSearch" />
97105
<!-- Main Content -->
@@ -103,3 +111,9 @@ onMounted(() => {
103111
</div>
104112
</main>
105113
</template>
114+
115+
<style scoped>
116+
main.dark {
117+
background-color: #222;
118+
}
119+
</style>

src/components/FilterSidebar.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,17 @@ function filter(event: Event) {
8080
width: 600px;
8181
padding: 1rem;
8282
}
83+
84+
main.dark .filter-content {
85+
color: #ddd;
86+
}
87+
88+
main.dark .filter-content .form-select {
89+
background-color: #444;
90+
color: #ddd;
91+
}
92+
93+
main.dark .filter-content .btn {
94+
color: #ddd;
95+
}
8396
</style>

src/components/LogTable.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { onMounted, onUnmounted, ref } from "vue";
2+
import { onMounted, onUnmounted, reactive, ref } from "vue";
33
import type { JournalEntries } from "@/model/JournalEntries";
44
55
const props = defineProps<{
@@ -10,6 +10,10 @@ const emit = defineEmits<{
1010
(e: "load-more"): void;
1111
}>();
1212
13+
let vm = reactive({
14+
tableTheme: "",
15+
});
16+
1317
const scrollComponent = ref<Element | null>(null);
1418
1519
type ColumnViewOptions = {
@@ -81,6 +85,12 @@ columnViewOptions.forEach((c, i) => {
8185
});
8286
8387
onMounted(() => {
88+
const match = window.matchMedia("(prefers-color-scheme: dark)");
89+
90+
if (match) {
91+
vm.tableTheme = "table-dark";
92+
}
93+
8494
window.addEventListener("scroll", handleScroll);
8595
});
8696
@@ -100,7 +110,7 @@ const getRowClass = (row: Array<string>) => `priority-${row[0]}`;
100110
<template>
101111
<!-- Log table -->
102112
<div class="container-fluid" ref="scrollComponent">
103-
<table class="table table-striped table-hover table-borderless table-sm">
113+
<table class="table table-striped table-hover table-borderless table-sm" :class="vm.tableTheme">
104114
<thead>
105115
<th v-for="c in columnViewOptions.filter((x) => x.visible)" :style="c.style">
106116
{{ c.name }}
@@ -191,6 +201,13 @@ const getRowClass = (row: Array<string>) => `priority-${row[0]}`;
191201
color: #666;
192202
}
193203
204+
main.dark .priority-6 {
205+
color: #bbb;
206+
}
207+
main.dark .table-striped > tbody > tr.priority-6:nth-of-type(odd) > * {
208+
color: #bbb;
209+
}
210+
194211
.priority-6 td:first-child div {
195212
width: 4px;
196213
height: 24px;
@@ -200,6 +217,13 @@ const getRowClass = (row: Array<string>) => `priority-${row[0]}`;
200217
color: #aaa;
201218
}
202219
220+
main.dark .priority-7 {
221+
color: #666;
222+
}
223+
main.dark .table-striped > tbody > tr.priority-7:nth-of-type(odd) > * {
224+
color: #666;
225+
}
226+
203227
.priority-7 td:first-child div {
204228
width: 4px;
205229
height: 24px;

src/components/SearchBar.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,16 @@ function search(event?: Event) {
4242
background-color: #e3f2fd;
4343
border: 1px solid #70b1df;
4444
}
45+
46+
main.dark .navbar {
47+
background-color: #1d4663;
48+
border: 1px solid #3078ac;
49+
}
50+
51+
main.dark .navbar-brand {
52+
color: #ddd;
53+
}
54+
main.dark .btn {
55+
color: #ddd;
56+
}
4557
</style>

src/components/SummaryBar.vue

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,24 @@ const getXLegendDate = (x: string, index: number) => {
145145
width: 98%;
146146
}
147147
148+
main.dark .summary-bar {
149+
background-color: #444;
150+
}
151+
148152
.summary-y-legend {
149153
position: absolute;
150154
left: 0;
151155
height: 100%;
152156
width: 100%;
153157
}
154158
159+
main.dark .summary-y-legend {
160+
color: #ddd;
161+
}
162+
155163
.summary-y-legend .y-legend {
156164
border-bottom: 1px solid #aaa;
157-
font-size: 0.4rem;
165+
font-size: 0.8rem;
158166
}
159167
160168
.summary-cell {
@@ -167,6 +175,10 @@ const getXLegendDate = (x: string, index: number) => {
167175
opacity: 0.6;
168176
}
169177
178+
main.dark .summary-cell:hover {
179+
background-color: #666;
180+
}
181+
170182
.summary-value {
171183
background-color: rgb(238, 133, 133);
172184
border: 1px solid rgb(228, 96, 96);
@@ -178,6 +190,11 @@ const getXLegendDate = (x: string, index: number) => {
178190
margin: 0 auto;
179191
}
180192
193+
main.dark .summary-value {
194+
background-color: rgb(192, 78, 78);
195+
border: 1px solid rgb(224, 14, 14);
196+
}
197+
181198
.summary-cell:hover .summary-value {
182199
background-color: rgb(255, 0, 0);
183200
opacity: 1;
@@ -187,8 +204,12 @@ const getXLegendDate = (x: string, index: number) => {
187204
position: absolute;
188205
bottom: -50px;
189206
rotate: 30deg;
190-
font-size: 0.6rem;
207+
font-size: 0.8rem;
191208
text-align: left;
192209
width: 100px;
193210
}
211+
212+
main.dark .summary-x-legend {
213+
color: #ddd;
214+
}
194215
</style>

0 commit comments

Comments
 (0)