Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
1f222e6c
Unverified
Commit
1f222e6c
authored
2 years ago
by
Andreas Nedbal
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(client): refactor settings/theme to use Composition API (#8595)
parent
0e26fae3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/client/src/pages/settings/theme.vue
+68
-91
68 additions, 91 deletions
packages/client/src/pages/settings/theme.vue
with
68 additions
and
91 deletions
packages/client/src/pages/settings/theme.vue
+
68
−
91
View file @
1f222e6c
...
...
@@ -85,12 +85,11 @@
</div>
</template>
<
script
lang=
"ts"
>
import
{
computed
,
defineComponent
,
onActivated
,
onMoun
ted
,
ref
,
watch
}
from
'
vue
'
;
<
script
lang=
"ts"
setup
>
import
{
computed
,
onActiva
ted
,
ref
,
watch
}
from
'
vue
'
;
import
JSON5
from
'
json5
'
;
import
FormSwitch
from
'
@/components/form/switch.vue
'
;
import
FormSelect
from
'
@/components/form/select.vue
'
;
import
FormGroup
from
'
@/components/form/group.vue
'
;
import
FormSection
from
'
@/components/form/section.vue
'
;
import
FormLink
from
'
@/components/form/link.vue
'
;
import
FormButton
from
'
@/components/ui/button.vue
'
;
...
...
@@ -101,100 +100,78 @@ import { ColdDeviceStorage } from '@/store';
import
{
i18n
}
from
'
@/i18n
'
;
import
{
defaultStore
}
from
'
@/store
'
;
import
{
instance
}
from
'
@/instance
'
;
import
{
concat
,
uniqueBy
}
from
'
@/scripts/array
'
;
import
{
uniqueBy
}
from
'
@/scripts/array
'
;
import
{
fetchThemes
,
getThemes
}
from
'
@/theme-store
'
;
import
*
as
symbols
from
'
@/symbols
'
;
export
default
defineComponent
({
components
:
{
FormSwitch
,
FormSelect
,
FormGroup
,
FormSection
,
FormLink
,
FormButton
,
const
installedThemes
=
ref
(
getThemes
());
const
instanceThemes
=
[];
if
(
instance
.
defaultLightTheme
!=
null
)
instanceThemes
.
push
(
JSON5
.
parse
(
instance
.
defaultLightTheme
));
if
(
instance
.
defaultDarkTheme
!=
null
)
instanceThemes
.
push
(
JSON5
.
parse
(
instance
.
defaultDarkTheme
));
const
themes
=
computed
(()
=>
uniqueBy
(
instanceThemes
.
concat
(
builtinThemes
.
concat
(
installedThemes
.
value
)),
theme
=>
theme
.
id
));
const
darkThemes
=
computed
(()
=>
themes
.
value
.
filter
(
t
=>
t
.
base
===
'
dark
'
||
t
.
kind
===
'
dark
'
));
const
lightThemes
=
computed
(()
=>
themes
.
value
.
filter
(
t
=>
t
.
base
===
'
light
'
||
t
.
kind
===
'
light
'
));
const
darkTheme
=
ColdDeviceStorage
.
ref
(
'
darkTheme
'
);
const
darkThemeId
=
computed
({
get
()
{
return
darkTheme
.
value
.
id
;
},
set
(
id
)
{
ColdDeviceStorage
.
set
(
'
darkTheme
'
,
themes
.
value
.
find
(
x
=>
x
.
id
===
id
))
}
});
const
lightTheme
=
ColdDeviceStorage
.
ref
(
'
lightTheme
'
);
const
lightThemeId
=
computed
({
get
()
{
return
lightTheme
.
value
.
id
;
},
set
(
id
)
{
ColdDeviceStorage
.
set
(
'
lightTheme
'
,
themes
.
value
.
find
(
x
=>
x
.
id
===
id
))
}
});
const
darkMode
=
computed
(
defaultStore
.
makeGetterSetter
(
'
darkMode
'
));
const
syncDeviceDarkMode
=
computed
(
ColdDeviceStorage
.
makeGetterSetter
(
'
syncDeviceDarkMode
'
));
const
wallpaper
=
ref
(
localStorage
.
getItem
(
'
wallpaper
'
));
const
themesCount
=
installedThemes
.
value
.
length
;
watch
(
syncDeviceDarkMode
,
()
=>
{
if
(
syncDeviceDarkMode
.
value
)
{
defaultStore
.
set
(
'
darkMode
'
,
isDeviceDarkmode
());
}
});
emits
:
[
'
info
'
],
setup
(
props
,
{
emit
})
{
const
INFO
=
{
title
:
i18n
.
ts
.
theme
,
icon
:
'
fas fa-palette
'
,
bg
:
'
var(--bg)
'
,
};
const
installedThemes
=
ref
(
getThemes
());
const
instanceThemes
=
[];
if
(
instance
.
defaultLightTheme
!=
null
)
instanceThemes
.
push
(
JSON5
.
parse
(
instance
.
defaultLightTheme
));
if
(
instance
.
defaultDarkTheme
!=
null
)
instanceThemes
.
push
(
JSON5
.
parse
(
instance
.
defaultDarkTheme
));
const
themes
=
computed
(()
=>
uniqueBy
(
instanceThemes
.
concat
(
builtinThemes
.
concat
(
installedThemes
.
value
)),
theme
=>
theme
.
id
));
const
darkThemes
=
computed
(()
=>
themes
.
value
.
filter
(
t
=>
t
.
base
===
'
dark
'
||
t
.
kind
===
'
dark
'
));
const
lightThemes
=
computed
(()
=>
themes
.
value
.
filter
(
t
=>
t
.
base
===
'
light
'
||
t
.
kind
===
'
light
'
));
const
darkTheme
=
ColdDeviceStorage
.
ref
(
'
darkTheme
'
);
const
darkThemeId
=
computed
({
get
()
{
return
darkTheme
.
value
.
id
;
},
set
(
id
)
{
ColdDeviceStorage
.
set
(
'
darkTheme
'
,
themes
.
value
.
find
(
x
=>
x
.
id
===
id
))
}
});
const
lightTheme
=
ColdDeviceStorage
.
ref
(
'
lightTheme
'
);
const
lightThemeId
=
computed
({
get
()
{
return
lightTheme
.
value
.
id
;
},
set
(
id
)
{
ColdDeviceStorage
.
set
(
'
lightTheme
'
,
themes
.
value
.
find
(
x
=>
x
.
id
===
id
))
}
});
const
darkMode
=
computed
(
defaultStore
.
makeGetterSetter
(
'
darkMode
'
));
const
syncDeviceDarkMode
=
computed
(
ColdDeviceStorage
.
makeGetterSetter
(
'
syncDeviceDarkMode
'
));
const
wallpaper
=
ref
(
localStorage
.
getItem
(
'
wallpaper
'
));
const
themesCount
=
installedThemes
.
value
.
length
;
watch
(
syncDeviceDarkMode
,
()
=>
{
if
(
syncDeviceDarkMode
.
value
)
{
defaultStore
.
set
(
'
darkMode
'
,
isDeviceDarkmode
());
}
});
watch
(
wallpaper
,
()
=>
{
if
(
wallpaper
.
value
==
null
)
{
localStorage
.
removeItem
(
'
wallpaper
'
);
}
else
{
localStorage
.
setItem
(
'
wallpaper
'
,
wallpaper
.
value
);
}
location
.
reload
();
});
watch
(
wallpaper
,
()
=>
{
if
(
wallpaper
.
value
==
null
)
{
localStorage
.
removeItem
(
'
wallpaper
'
);
}
else
{
localStorage
.
setItem
(
'
wallpaper
'
,
wallpaper
.
value
);
}
location
.
reload
();
});
onActivated
(()
=>
{
fetchThemes
().
then
(()
=>
{
installedThemes
.
value
=
getThemes
();
});
});
fetchThemes
().
then
(()
=>
{
installedThemes
.
value
=
getThemes
();
});
return
{
[
symbols
.
PAGE_INFO
]:
INFO
,
darkThemes
,
lightThemes
,
darkThemeId
,
lightThemeId
,
darkMode
,
syncDeviceDarkMode
,
themesCount
,
wallpaper
,
setWallpaper
(
e
)
{
selectFile
(
e
.
currentTarget
??
e
.
target
,
null
).
then
(
file
=>
{
wallpaper
.
value
=
file
.
url
;
});
},
};
onActivated
(()
=>
{
fetchThemes
().
then
(()
=>
{
installedThemes
.
value
=
getThemes
();
});
});
fetchThemes
().
then
(()
=>
{
installedThemes
.
value
=
getThemes
();
});
function
setWallpaper
(
event
)
{
selectFile
(
event
.
currentTarget
??
event
.
target
,
null
).
then
(
file
=>
{
wallpaper
.
value
=
file
.
url
;
});
}
defineExpose
({
[
symbols
.
PAGE_INFO
]:
{
title
:
i18n
.
ts
.
theme
,
icon
:
'
fas fa-palette
'
,
bg
:
'
var(--bg)
'
,
}
});
</
script
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment