Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change User instead of Workspace settings. #56

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vscode-extension/src/common/WorkspaceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export interface WorkspaceConfigEventListener<T> {

export interface WorkspaceConfig {
getConfig(): Promise<WorkspaceConfigProps>;
// update method can take any of the keys from WorkspaceConfigProps and appropriate value:
update<K extends keyof WorkspaceConfigProps>(
// updateUserLevel method can take any of the keys from WorkspaceConfigProps and appropriate value:
updateUserLevel<K extends keyof WorkspaceConfigProps>(
key: K,
value: WorkspaceConfigProps[K]
): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ export class WorkspaceConfigController implements Disposable, WorkspaceConfig {
return this.config;
}

async update<K extends keyof WorkspaceConfigProps>(key: K, value: WorkspaceConfigProps[K]) {
async updateUserLevel<K extends keyof WorkspaceConfigProps>(
key: K,
value: WorkspaceConfigProps[K]
) {
const configuration = workspace.getConfiguration("ReactNativeIDE");
await configuration.update(key as string, value);
await configuration.update(key as string, value, true);
}

async addListener<K extends keyof WorkspaceConfigEventMap>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface SettingsDropdownProps {
}

function SettingsDropdown({ project, children, disabled }: SettingsDropdownProps) {
const { panelLocation, update } = useWorkspaceConfig();
const { panelLocation, updateUserLevel } = useWorkspaceConfig();
const { openModal } = useModal();
return (
<DropdownMenu.Root>
Expand Down Expand Up @@ -55,14 +55,14 @@ function SettingsDropdown({ project, children, disabled }: SettingsDropdownProps
alignOffset={-5}>
<DropdownMenu.Item
className="dropdown-menu-item"
onSelect={() => update("panelLocation", "tab")}>
onSelect={() => updateUserLevel("panelLocation", "tab")}>
<span className="codicon codicon-layout-centered" />
Editor tab
{panelLocation === "tab" && <span className="codicon codicon-check right-slot" />}
</DropdownMenu.Item>
<DropdownMenu.Item
className="dropdown-menu-item"
onSelect={() => update("panelLocation", "side-panel")}>
onSelect={() => updateUserLevel("panelLocation", "side-panel")}>
<span className="codicon codicon-layout-sidebar-right" />
Side panel
{panelLocation === "side-panel" && (
Expand All @@ -72,7 +72,7 @@ function SettingsDropdown({ project, children, disabled }: SettingsDropdownProps
<DropdownMenu.Item
className="dropdown-menu-item"
onSelect={() => {
update("panelLocation", "secondary-side-panel");
updateUserLevel("panelLocation", "secondary-side-panel");
openModal(
"Drag and drop to secondary side panel",
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import { WorkspaceConfig, WorkspaceConfigProps } from "../../common/WorkspaceCon
const workspaceConfig = makeProxy<WorkspaceConfig>("WorkspaceConfig");

type WorkspaceConfigContextType = WorkspaceConfigProps & {
update: <K extends keyof WorkspaceConfigProps>(key: K, value: WorkspaceConfigProps[K]) => void;
updateUserLevel: <K extends keyof WorkspaceConfigProps>(
key: K,
value: WorkspaceConfigProps[K]
) => void;
};

const WorkspaceConfigContext = createContext<WorkspaceConfigContextType>({
panelLocation: "tab",
relativeAppLocation: "",
update: () => {},
updateUserLevel: () => {},
});

export default function WorkspaceConfigProvider({ children }: PropsWithChildren) {
Expand All @@ -36,17 +39,21 @@ export default function WorkspaceConfigProvider({ children }: PropsWithChildren)
};
}, []);

const update = useCallback(
<K extends keyof WorkspaceConfigProps>(key: K, value: WorkspaceConfigProps[K]) => {
const updateUserLevel = useCallback(
<K extends keyof WorkspaceConfigProps>(
key: K,
value: WorkspaceConfigProps[K],
configurationTarget?: boolean
) => {
const newState = { ...config, [key]: value };
setConfig(newState);
workspaceConfig.update(key, value);
workspaceConfig.updateUserLevel(key, value);
},
[config, setConfig]
);

return (
<WorkspaceConfigContext.Provider value={{ ...config, update }}>
<WorkspaceConfigContext.Provider value={{ ...config, updateUserLevel }}>
{children}
</WorkspaceConfigContext.Provider>
);
Expand Down
Loading