mirror of
https://github.com/filecoin-project/slate.git
synced 2024-09-11 22:07:08 +03:00
feat(db/users):
- remove settings column - add isFilterSidebarCollapsed column
This commit is contained in:
parent
0c84d22bde
commit
dd3f46f0c9
@ -7,40 +7,38 @@ const UploadContext = React.createContext({});
|
||||
export const useFilterContext = () => React.useContext(UploadContext);
|
||||
|
||||
export const Provider = ({ children, viewer }) => {
|
||||
const [isSidebarVisible, toggleSidebar] = useFilterSidebar({ viewer });
|
||||
const [isSidebarCollapsed, toggleSidebar] = useFilterSidebar({ viewer });
|
||||
|
||||
const [isPopupVisible, { hidePopup, togglePopup }] = useFilterPopup();
|
||||
|
||||
const contextValue = React.useMemo(
|
||||
() => [
|
||||
{
|
||||
sidebarState: { isVisible: isSidebarVisible },
|
||||
sidebarState: { isVisible: !isSidebarCollapsed },
|
||||
popupState: { isVisible: isPopupVisible },
|
||||
},
|
||||
{ toggleSidebar, hidePopup, togglePopup },
|
||||
],
|
||||
[isSidebarVisible, isPopupVisible]
|
||||
[isSidebarCollapsed, isPopupVisible]
|
||||
);
|
||||
|
||||
return <UploadContext.Provider value={contextValue}>{children}</UploadContext.Provider>;
|
||||
};
|
||||
|
||||
const useFilterSidebar = ({ viewer }) => {
|
||||
const initialState =
|
||||
typeof viewer?.settings?.isSidebarVisible === "undefined"
|
||||
? true
|
||||
: viewer.settings.isSidebarVisible;
|
||||
const initialState = viewer?.isFilterSidebarCollapsed;
|
||||
|
||||
const [isSidebarVisible, setSidebarState] = React.useState(initialState);
|
||||
const [isSidebarCollapsed, setSidebarState] = React.useState(initialState);
|
||||
const toggleSidebar = async () => {
|
||||
setSidebarState((prev) => !prev);
|
||||
const nextState = !isSidebarCollapsed;
|
||||
setSidebarState(nextState);
|
||||
const response = await Actions.updateViewer({
|
||||
user: { settings: { isSidebarVisible: !isSidebarVisible } },
|
||||
user: { isFilterSidebarCollapsed: nextState },
|
||||
});
|
||||
Events.hasError(response);
|
||||
};
|
||||
|
||||
return [isSidebarVisible, toggleSidebar];
|
||||
return [isSidebarCollapsed, toggleSidebar];
|
||||
};
|
||||
|
||||
const useFilterPopup = () => {
|
||||
|
@ -37,10 +37,6 @@ export default async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (updates.settings) {
|
||||
updates.settings = { ...user.settings, ...updates.settings };
|
||||
}
|
||||
|
||||
if (updates.onboarding) {
|
||||
updates.onboarding = { ...user.onboarding, ...updates.onboarding };
|
||||
}
|
||||
|
@ -100,13 +100,33 @@ const createSurveysTable = (async () => {
|
||||
})();
|
||||
|
||||
const dropOnboardingTable = db.schema.dropTableIfExists("onboarding");
|
||||
|
||||
const addOnboardingColumnsToUsersTable = db.schema.table("users", function (table) {
|
||||
table.boolean("hasCompletedSurvey").defaultTo(false);
|
||||
table.boolean("hasCompletedUploadOnboarding").defaultTo(false);
|
||||
table.boolean("hasCompletedSlatesOnboarding").defaultTo(false);
|
||||
});
|
||||
|
||||
Promise.all([dropOnboardingTable, createSurveysTable, addOnboardingColumnsToUsersTable]);
|
||||
const deleteSettingsColumnFromUserTable = (async () => {
|
||||
const hasColumn = await db.schema.hasColumn("users", "settings");
|
||||
if (hasColumn) {
|
||||
return db.schema.alterTable("users", (table) => {
|
||||
table.dropColumn("settings");
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
const addIsFilterSidebarCollapsedToUsersTable = db.schema.table("users", function (table) {
|
||||
table.boolean("isFilterSidebarCollapsed").defaultTo(false);
|
||||
});
|
||||
|
||||
Promise.all([
|
||||
dropOnboardingTable,
|
||||
createSurveysTable,
|
||||
addOnboardingColumnsToUsersTable,
|
||||
deleteSettingsColumnFromUserTable,
|
||||
addIsFilterSidebarCollapsedToUsersTable,
|
||||
]);
|
||||
|
||||
Logging.log(`FINISHED: adjust.js`);
|
||||
Logging.log(` CTRL +C to return to terminal.`);
|
||||
|
@ -53,6 +53,10 @@ const createUsersTable = createTableIfNotExists("users", function (table) {
|
||||
table.integer("followerCount").notNullable().defaultTo(0);
|
||||
table.integer("slateCount").notNullable().defaultTo(0);
|
||||
table.integer("authVersion").notNullable().defaultTo(2);
|
||||
table.boolean("hasCompletedSurvey").defaultTo(false);
|
||||
table.boolean("hasCompletedUploadOnboarding").defaultTo(false);
|
||||
table.boolean("hasCompletedSlatesOnboarding").defaultTo(false);
|
||||
table.boolean("isFilterSidebarCollapsed").defaultTo(false);
|
||||
});
|
||||
|
||||
const createSlatesTable = createTableIfNotExists("slates", function (table) {
|
||||
|
Loading…
Reference in New Issue
Block a user