diff --git a/CHANGELOG.md b/CHANGELOG.md index 323375c4..07df5070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Support `fieldGroup` as a single value on `fields` fields - [#1030](https://github.com/estruyf/vscode-front-matter/pull/1030): Add `frontMatter.file.slugSeparator` setting - [#1033](https://github.com/estruyf/vscode-front-matter/issues/1033): Support freeform tags and categories in the front matter validation +- [#1036](https://github.com/estruyf/vscode-front-matter/issues/1036): Default filter, sorting, and grouping configuration for the `contents` dashboard ### 🐞 Fixes diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 76f21207..8e297335 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -211,6 +211,7 @@ "dashboard.header.sorting.alt.asc": "Alt (asc)", "dashboard.header.sorting.alt.desc": "Alt (desc)", "dashboard.header.sorting.label": "Sort by", + "dashboard.header.sorting.default": "Default", "dashboard.header.startup.label": "Open on startup?", diff --git a/package.json b/package.json index aaee9722..e4e57b91 100644 --- a/package.json +++ b/package.json @@ -726,6 +726,28 @@ "markdownDescription": "%setting.frontMatter.dashboard.content.pagination.markdownDescription%", "scope": "Dashboard" }, + "frontMatter.dashboard.content.defaults": { + "type": "object", + "markdownDescription": "%setting.frontMatter.dashboard.content.defaults.markdownDescription%", + "scope": "Dashboard", + "properties": { + "sorting": { + "type": "string", + "description": "%setting.frontMatter.dashboard.content.defaults.properties.sorting.description%" + }, + "grouping": { + "type": "string", + "description": "%setting.frontMatter.dashboard.content.defaults.properties.grouping.description%" + }, + "filters": { + "type": "object", + "description": "%setting.frontMatter.dashboard.content.defaults.properties.filters.description%", + "additionalProperties": { + "type": "string" + } + } + } + }, "frontMatter.dashboard.content.cardTags": { "type": "string", "default": "tags", diff --git a/package.nls.json b/package.nls.json index 091f77b0..353add82 100644 --- a/package.nls.json +++ b/package.nls.json @@ -123,6 +123,10 @@ "setting.frontMatter.custom.scripts.items.properties.environments.items.properties.script.description": "Path to the script to execute", "setting.frontMatter.custom.scripts.items.properties.contentTypes.description": "Define the content types for which the script will be used. If none are defined, it will be available to all types.", "setting.frontMatter.dashboard.content.pagination.markdownDescription": "Specify if you want to enable/disable pagination for your content. You can define your page number up to 52. Default items per page is `16`. Disabling the pagination can be done by setting it to `false`. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.dashboard.content.pagination) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.dashboard.content.pagination%22%5D)", + "setting.frontMatter.dashboard.content.defaults.markdownDescription": "Configure the default opening state of the contents dashboard, including sorting, grouping, and filters.", + "setting.frontMatter.dashboard.content.defaults.properties.sorting.description": "The default sorting option for the contents dashboard. Use a built-in sort ID (e.g. LastModifiedDesc) or a custom sorting option ID.", + "setting.frontMatter.dashboard.content.defaults.properties.grouping.description": "The default grouping for the contents dashboard. Use Year, Draft, None, or a custom grouping name.", + "setting.frontMatter.dashboard.content.defaults.properties.filters.description": "The default filter values for the contents dashboard. Keys can be contentFolders, tags, categories, or a custom filter name.", "setting.frontMatter.dashboard.content.cardTags.markdownDescription": "Specify the name of the metadata field that will be used to show the tags on the content card. When empty or null, it will hide the tags from the card. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.dashboard.content.cardtags) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.dashboard.content.cardtags%22%5D)", "setting.frontMatter.dashboard.content.card.fields.state.markdownDescription": "Specify if you want to show the state/draft status on the content card view. [Docs](https://frontmatter.codes/docs/settings/overview#frontMatter.dashboard.content.card.fields.state) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontMatter.dashboard.content.card.fields.state%22%5D)", "setting.frontMatter.dashboard.content.card.fields.date.markdownDescription": "Specify if you want to show the date on the content card view. [Docs](https://frontmatter.codes/docs/settings/overview#frontMatter.dashboard.content.card.fields.date) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontMatter.dashboard.content.card.fields.date%22%5D)", @@ -173,7 +177,6 @@ "setting.frontMatter.global.timezone.markdownDescription": "Specify the timezone for your date formatting. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.taxonomy.datetimezone) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.taxonomy.datetimezone%22%5D)", "setting.frontMatter.media.defaultSorting.markdownDescription": "Specify the default sorting option for the media dashboard. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.media.defaultsorting) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.media.defaultsorting%22%5D)", "setting.frontMatter.media.supportedMimeTypes.markdownDescription": "Specify the mime types to support for the media files. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.media.supportedmimetypes) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.media.supportedmimetypes%22%5D)", - "setting.frontMatter.media.contentTypes.markdownDescription": "Specify the media content types you want to use in Front Matter. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.media.contenttypes) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.media.contenttypes%22%5D)", "setting.frontMatter.media.contentTypes.items.description": "Define the media content types you want to use in Front Matter.", "setting.frontMatter.media.contentTypes.items.properties.name.description": "Name of the media content type", @@ -183,7 +186,6 @@ "setting.frontMatter.media.contentTypes.items.properties.fields.properties.name.description": "Name of the field to use", "setting.frontMatter.media.contentTypes.items.properties.fields.properties.type.description": "Define the type of field", "setting.frontMatter.media.contentTypes.items.properties.fields.properties.single.description": "Is a single line field", - "setting.frontMatter.panel.openOnSupportedFile.markdownDescription": "Specifies if you want to open the panel when opening a supported file. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.panel.openonsupportedfile) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.panel.openonsupportedfile%22%5D)", "setting.frontMatter.panel.freeform.markdownDescription": "Specifies whether the tag picker should allow unknown tags and categories. When enabled, you can enter new values and save them afterward. Default: true. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.panel.freeform) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.panel.freeform%22%5D)", "setting.frontMatter.panel.actions.disabled.markdownDescription": "Specify the actions you want to disable in the panel. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.panel.actions.disabled) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.panel.actions.disabled%22%5D)", @@ -290,7 +292,6 @@ "setting.frontMatter.config.dynamicFilePath.markdownDescription": "Specify the path to the dynamic config file (ex: [[workspace]]/config.js). [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.config.dynamicfilepath) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.config.dynamicfilepath%22%5D)", "setting.frontMatter.taxonomy.contentTypes.items.properties.allowAsSubContent.description": "Specify if the content type can be used as sub content.", "setting.frontMatter.taxonomy.contentTypes.items.properties.isSubContent.description": "Specify if the content type is sub content.", - "setting.frontMatter.git.disableOnBranches.markdownDescription": "Specify the branches on which you want to disable the Git actions. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.git.disableonbranches) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.git.disableonbranches%22%5D)", "setting.frontMatter.git.requiresCommitMessage.markdownDescription": "Specify if you want to require a commit message when publishing your changes for a specified branch. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.git.requirescommitmessage) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.git.requirescommitmessage%22%5D)", "setting.frontMatter.copilot.family.markdownDescription": "Specify the LLM family of the Copilot you want to use. [Docs](https://frontmatter.codes/docs/settings/overview#frontmatter.copilot.family) - [View in VS Code](command:simpleBrowser.show?%5B%22https://frontmatter.codes/docs/settings/overview%23frontmatter.copilot.family%22%5D)", diff --git a/src/constants/settings.ts b/src/constants/settings.ts index f13a298e..96e1dd8a 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -84,6 +84,7 @@ export const SETTING_MEDIA_CONTENTTYPES = 'media.contentTypes'; export const SETTING_DASHBOARD_OPENONSTART = 'dashboard.openOnStart'; export const SETTING_DASHBOARD_CONTENT_TAGS = 'dashboard.content.cardTags'; export const SETTING_DASHBOARD_CONTENT_PAGINATION = 'dashboard.content.pagination'; +export const SETTING_DASHBOARD_CONTENT_DEFAULTS = 'dashboard.content.defaults'; // Content cards export const SETTING_DASHBOARD_CONTENT_CARD_STATE = 'dashboard.content.card.fields.state'; diff --git a/src/dashboardWebView/DashboardMessage.ts b/src/dashboardWebView/DashboardMessage.ts index 8db1af4a..579d6b87 100644 --- a/src/dashboardWebView/DashboardMessage.ts +++ b/src/dashboardWebView/DashboardMessage.ts @@ -79,6 +79,7 @@ export enum DashboardMessage { updateSetting = 'updateSetting', setState = 'setState', getState = 'getState', + clearState = 'clearState', runCustomScript = 'runCustomScript', showNotification = 'showNotification', setTitle = 'setTitle', diff --git a/src/dashboardWebView/components/Header/Sorting.tsx b/src/dashboardWebView/components/Header/Sorting.tsx index 3b1ddaad..45db5c37 100644 --- a/src/dashboardWebView/components/Header/Sorting.tsx +++ b/src/dashboardWebView/components/Header/Sorting.tsx @@ -13,6 +13,7 @@ import { Sorting as SortingHelpers } from '../../../helpers/Sorting'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../../localization'; import { DropdownMenu, DropdownMenuContent } from '../../../components/shadcn/Dropdown'; +import { getSortingOptions, resolveSortingOption } from '../../utils'; export interface ISortingProps { disableCustomSorting?: boolean; @@ -23,6 +24,7 @@ export const Sorting: React.FunctionComponent = ({ disableCustomSorting, view }: React.PropsWithChildren) => { + const DEFAULT_SORT_LABEL = l10n.t(LocalizationKey.dashboardHeaderSortingDefault); const [crntSorting, setCrntSorting] = useRecoilState(SortingAtom); const searchValue = useRecoilValue(SearchSelector); const settings = useRecoilValue(SettingsSelector); @@ -109,14 +111,20 @@ export const Sorting: React.FunctionComponent = ({ } ]; - const updateSorting = (value: SortingOption) => { - Messenger.send(DashboardMessage.setState, { - key: `${view === NavigationType.Contents - ? ExtensionState.Dashboard.Contents.Sorting - : ExtensionState.Dashboard.Media.Sorting - }`, - value: value - }); + const updateSorting = (value: SortingOption | null) => { + if (value === null) { + messageHandler.send(DashboardMessage.clearState, { + key: view === NavigationType.Media ? ExtensionState.Dashboard.Media.Sorting : ExtensionState.Dashboard.Contents.Sorting + }); + } else { + Messenger.send(DashboardMessage.setState, { + key: `${view === NavigationType.Contents + ? ExtensionState.Dashboard.Contents.Sorting + : ExtensionState.Dashboard.Media.Sorting + }`, + value: value + }); + } setCrntSorting(value); }; @@ -147,51 +155,57 @@ export const Sorting: React.FunctionComponent = ({ React.useEffect(() => { const getSorting = async () => { let crntSortingOption = crntSorting; + let persistedSorting: SortingOption | null = null; + if (!crntSortingOption) { const sortingState = await messageHandler.request<{ key: string; value: SortingOption; }>(DashboardMessage.getState, { key: view === NavigationType.Media ? ExtensionState.Dashboard.Media.Sorting : ExtensionState.Dashboard.Contents.Sorting }); - crntSortingOption = sortingState?.value || null; - - if (crntSortingOption === null) { - if (view === NavigationType.Contents && settings?.dashboardState.contents.defaultSorting) { - crntSortingOption = - allOptions.find((f) => f.id === settings?.dashboardState.contents.defaultSorting) || null; - } else if ( - view === NavigationType.Media && - settings?.dashboardState.media.defaultSorting - ) { - crntSortingOption = - allOptions.find((f) => f.id === settings?.dashboardState.media.defaultSorting) || null; - } - } + persistedSorting = sortingState?.value || null; } - const sort = allOptions.find((x) => x.id === crntSortingOption?.id) || sortOptions[0]; + crntSortingOption = resolveSortingOption({ + currentSorting: crntSortingOption, + persistedSorting, + settings: settings || null, + view, + allOptions: getSortingOptions(view, settings?.customSorting, disableCustomSorting) + }); + + if (!crntSorting && crntSortingOption && persistedSorting === null) { + setCrntSorting(crntSortingOption); + } + + const sort = crntSortingOption + ? allOptions.find((x) => x.id === crntSortingOption?.id) || sortOptions[0] + : null; setCrntSort(sort); }; getSorting(); }, [crntSorting]); - if (crntSort === null) { - return null; - } - return ( + updateSorting(null)} + /> + {allOptions.map((option) => ( updateSorting(value)} /> ))} diff --git a/src/dashboardWebView/hooks/useMessages.tsx b/src/dashboardWebView/hooks/useMessages.tsx index f62e670f..14848e77 100644 --- a/src/dashboardWebView/hooks/useMessages.tsx +++ b/src/dashboardWebView/hooks/useMessages.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useRef } from 'react'; import { useRecoilState } from 'recoil'; import { DashboardCommand } from '../DashboardCommand'; import { DashboardMessage } from '../DashboardMessage'; @@ -9,7 +9,12 @@ import { SettingsAtom, ViewDataAtom, SearchReadyAtom, - ModeAtom + ModeAtom, + GroupingAtom, + FolderAtom, + FiltersAtom, + TagAtom, + CategoryAtom } from '../state'; import { Messenger, messageHandler } from '@estruyf/vscode/dist/client'; import { EventData } from '@estruyf/vscode/dist/models'; @@ -17,6 +22,7 @@ import { NavigationType } from '../models'; import { GeneralCommands } from '../../constants'; import { useNavigate } from 'react-router-dom'; import { routePaths } from '..'; +import { GroupOption } from '../constants/GroupOption'; export default function useMessages() { const navigate = useNavigate(); @@ -27,6 +33,12 @@ export default function useMessages() { const [, setMode] = useRecoilState(ModeAtom); const [, setView] = useRecoilState(DashboardViewAtom); const [, setSearchReady] = useRecoilState(SearchReadyAtom); + const [, setGrouping] = useRecoilState(GroupingAtom); + const [, setFolder] = useRecoilState(FolderAtom); + const [, setFilters] = useRecoilState(FiltersAtom); + const [, setTag] = useRecoilState(TagAtom); + const [, setCategory] = useRecoilState(CategoryAtom); + const defaultsApplied = useRef(false); const messageListener = (event: MessageEvent>) => { const message = event.data; @@ -61,6 +73,35 @@ export default function useMessages() { break; case DashboardCommand.settings: setSettings(message.payload); + if (!defaultsApplied.current) { + defaultsApplied.current = true; + const defaults = message.payload?.dashboardState?.contents?.defaults; + if (defaults) { + if (defaults.grouping) { + const GROUPING_MAP: { [key: string]: GroupOption } = { + Year: GroupOption.Year, + Draft: GroupOption.Draft, + None: GroupOption.none + }; + setGrouping(GROUPING_MAP[defaults.grouping] ?? (defaults.grouping as any)); + } + if (defaults.filters) { + const { contentFolders, tags, categories, ...customFilters } = defaults.filters; + if (contentFolders) { + setFolder(contentFolders); + } + if (tags) { + setTag(tags); + } + if (categories) { + setCategory(categories); + } + if (Object.keys(customFilters).length > 0) { + setFilters(customFilters); + } + } + } + } break; case DashboardCommand.pages: setPages(message.payload); diff --git a/src/dashboardWebView/hooks/usePages.tsx b/src/dashboardWebView/hooks/usePages.tsx index ef17824a..2a8e4586 100644 --- a/src/dashboardWebView/hooks/usePages.tsx +++ b/src/dashboardWebView/hooks/usePages.tsx @@ -27,6 +27,8 @@ import { ExtensionState, GeneralCommands } from '../../constants'; import { SortingOption } from '../models'; import { I18nConfig } from '../../models'; import { usePrevious } from '../../panelWebView/hooks/usePrevious'; +import { getSortingOptions, resolveSortingOption } from '../utils'; +import { NavigationType } from '../models/NavigationType'; export default function usePages(pages: Page[]) { const [sortedPages, setSortedPages] = useState([]); @@ -266,6 +268,19 @@ export default function usePages(pages: Page[]) { setSorting(value); return; } else { + const fallbackSorting = resolveSortingOption({ + currentSorting: null, + persistedSorting: value || null, + settings: settings || null, + view: NavigationType.Contents, + allOptions: getSortingOptions(NavigationType.Contents, settings?.customSorting) + }); + + if (fallbackSorting) { + setSorting(fallbackSorting); + return; + } + startPageProcessing(); } }); diff --git a/src/dashboardWebView/models/Settings.ts b/src/dashboardWebView/models/Settings.ts index d6e147a9..c8173daa 100644 --- a/src/dashboardWebView/models/Settings.ts +++ b/src/dashboardWebView/models/Settings.ts @@ -66,6 +66,12 @@ export interface DashboardState { welcome: WelcomeViewState; } +export interface ContentDefaults { + sorting?: string; + grouping?: string; + filters?: { [key: string]: string }; +} + export interface ContentsViewState { sorting: SortingOption | null | undefined; defaultSorting: string | null | undefined; @@ -73,6 +79,7 @@ export interface ContentsViewState { templatesEnabled: boolean | null | undefined; pagination: boolean | number | null | undefined; cardFields: CardFields; + defaults?: ContentDefaults; } export interface CardFields { diff --git a/src/dashboardWebView/utils/index.ts b/src/dashboardWebView/utils/index.ts index e8fd1757..75f53e84 100644 --- a/src/dashboardWebView/utils/index.ts +++ b/src/dashboardWebView/utils/index.ts @@ -3,4 +3,5 @@ export * from './darkenColor'; export * from './getRelPath'; export * from './opacityColor'; export * from './preserveColor'; +export * from './sorting'; export * from './updateCssVariables'; diff --git a/src/dashboardWebView/utils/sorting.ts b/src/dashboardWebView/utils/sorting.ts new file mode 100644 index 00000000..8a967e1d --- /dev/null +++ b/src/dashboardWebView/utils/sorting.ts @@ -0,0 +1,143 @@ +import { SortOrder, SortType, SortingSetting } from '../../models'; +import { SortOption } from '../constants/SortOption'; +import { NavigationType, Settings, SortingOption } from '../models'; + +const BASE_SORT_OPTIONS: SortingOption[] = [ + { + name: SortOption.LastModifiedAsc, + id: SortOption.LastModifiedAsc, + order: SortOrder.asc, + type: SortType.date + }, + { + name: SortOption.LastModifiedDesc, + id: SortOption.LastModifiedDesc, + order: SortOrder.desc, + type: SortType.date + }, + { + name: SortOption.FileNameAsc, + id: SortOption.FileNameAsc, + order: SortOrder.asc, + type: SortType.string + }, + { + name: SortOption.FileNameDesc, + id: SortOption.FileNameDesc, + order: SortOrder.desc, + type: SortType.string + } +]; + +const CONTENT_SORT_OPTIONS: SortingOption[] = [ + { + name: SortOption.PublishedAsc, + id: SortOption.PublishedAsc, + order: SortOrder.asc, + type: SortType.date + }, + { + name: SortOption.PublishedDesc, + id: SortOption.PublishedDesc, + order: SortOrder.desc, + type: SortType.date + } +]; + +const MEDIA_SORT_OPTIONS: SortingOption[] = [ + { + name: SortOption.SizeAsc, + id: SortOption.SizeAsc, + order: SortOrder.asc, + type: SortType.number + }, + { + name: SortOption.SizeDesc, + id: SortOption.SizeDesc, + order: SortOrder.desc, + type: SortType.number + }, + { + name: SortOption.CaptionAsc, + id: SortOption.CaptionAsc, + order: SortOrder.asc, + type: SortType.string + }, + { + name: SortOption.CaptionDesc, + id: SortOption.CaptionDesc, + order: SortOrder.desc, + type: SortType.string + }, + { + name: SortOption.AltAsc, + id: SortOption.AltAsc, + order: SortOrder.asc, + type: SortType.string + }, + { + name: SortOption.AltDesc, + id: SortOption.AltDesc, + order: SortOrder.desc, + type: SortType.string + } +]; + +export const getSortingOptions = ( + view: NavigationType, + customSorting: SortingSetting[] | undefined, + disableCustomSorting = false +) => { + let options = [...BASE_SORT_OPTIONS]; + + if (view === NavigationType.Media) { + options = [...options, ...MEDIA_SORT_OPTIONS]; + } else if (view === NavigationType.Contents) { + options = [...CONTENT_SORT_OPTIONS, ...options]; + } + + if (customSorting && !disableCustomSorting) { + options = [ + ...options, + ...customSorting.map((s) => ({ + title: s.title || s.name, + name: s.name, + id: s.id || `${s.name}-${s.order}`, + order: s.order, + type: s.type + })) + ]; + } + + return options; +}; + +export const resolveSortingOption = ({ + currentSorting, + persistedSorting, + settings, + view, + allOptions +}: { + currentSorting: SortingOption | null | undefined; + persistedSorting: SortingOption | null | undefined; + settings: Settings | null; + view: NavigationType; + allOptions: SortingOption[]; +}) => { + let sorting = currentSorting || persistedSorting || null; + + if (sorting === null) { + const defaultSortingId = + view === NavigationType.Contents + ? settings?.dashboardState.contents.defaults?.sorting || + settings?.dashboardState.contents.defaultSorting + : settings?.dashboardState.media.defaultSorting; + + if (defaultSortingId) { + sorting = allOptions.find((f) => f.id === defaultSortingId) || null; + } + } + + return sorting; +}; diff --git a/src/helpers/DashboardSettings.ts b/src/helpers/DashboardSettings.ts index 1ddfe164..cbdafd8c 100644 --- a/src/helpers/DashboardSettings.ts +++ b/src/helpers/DashboardSettings.ts @@ -32,12 +32,14 @@ import { SETTING_DASHBOARD_CONTENT_CARD_DESCRIPTION, SETTING_WEBSITE_URL, SETTING_MEDIA_CONTENTTYPES, - SETTING_PANEL_OPEN_ON_SUPPORTED_FILE + SETTING_PANEL_OPEN_ON_SUPPORTED_FILE, + SETTING_DASHBOARD_CONTENT_DEFAULTS } from '../constants'; import { DashboardViewType, SortingOption, - Settings as ISettings + Settings as ISettings, + ContentDefaults } from '../dashboardWebView/models'; import { CustomScript, @@ -143,7 +145,8 @@ export class DashboardSettings { date: Settings.get(SETTING_DASHBOARD_CONTENT_CARD_DATE), title: Settings.get(SETTING_DASHBOARD_CONTENT_CARD_TITLE), description: Settings.get(SETTING_DASHBOARD_CONTENT_CARD_DESCRIPTION) - } + }, + defaults: Settings.get(SETTING_DASHBOARD_CONTENT_DEFAULTS) }, media: { sorting: await ext.getState( diff --git a/src/listeners/dashboard/ExtensionListener.ts b/src/listeners/dashboard/ExtensionListener.ts index 9a594d1a..c5f8d9fa 100644 --- a/src/listeners/dashboard/ExtensionListener.ts +++ b/src/listeners/dashboard/ExtensionListener.ts @@ -27,15 +27,25 @@ export class ExtensionListener extends BaseListener { case DashboardMessage.setState: this.setState(msg?.payload); break; + case DashboardMessage.clearState: + this.clearState(msg?.payload); + break; case DashboardMessage.getState: this.getState(msg.command, msg?.payload, msg.requestId); break; } } + private static clearState(data: any) { + const { key } = data; + if (key) { + Extension.getInstance().setState(key, undefined, 'workspace'); + } + } + private static setState(data: any) { const { key, value } = data; - if (key && value) { + if (key && typeof value !== 'undefined') { Extension.getInstance().setState(key, value, 'workspace'); } } diff --git a/src/localization/localization.enum.ts b/src/localization/localization.enum.ts index 46145bc6..fb53ef77 100644 --- a/src/localization/localization.enum.ts +++ b/src/localization/localization.enum.ts @@ -695,6 +695,10 @@ export enum LocalizationKey { * Sort by */ dashboardHeaderSortingLabel = 'dashboard.header.sorting.label', + /** + * Default + */ + dashboardHeaderSortingDefault = 'dashboard.header.sorting.default', /** * Open on startup? */